PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
PPoolTimer< Work_T, Pool_T > Class Template Referenceabstract

Template abstract class for a PTimer that queues a work item to a thread pool. More...

`#include <timer.h>`

Inheritance diagram for PPoolTimer< Work_T, Pool_T >:
[legend]
Collaboration diagram for PPoolTimer< Work_T, Pool_T >:
[legend]

## Public Member Functions
| PPoolTimer (Pool_T &pool)
virtual void | OnTimeout ()
| This function is called on time out. More...
virtual Work_T * | CreateWork ()=0
virtual const char * | GetGroup (const Work_T &) const
| PTIMER_OPERATORS (PPoolTimer)
Public Member Functions inherited from PTimer
IDType | GetTimerId () const
PAtomicInteger::IntegerType | GetNextSerialNumber ()
| PTimer (long milliseconds=0, int seconds=0, int minutes=0, int hours=0, int days=0)
| Create a new timer object and start it in one shot mode for the specified amount of time. More...
| PTimer (const PTimeInterval &time)
| PTimer (const PTimer &timer)
PTimer & | operator= (const PTimer &timer)
| Restart the timer in one shot mode using the specified time value. More...
| PTIMER_OPERATORS (PTimer)
virtual | ~PTimer ()
| Destroy the timer object, removing it from the applications timer list if it was running. More...
virtual void | SetInterval (PInt64 milliseconds=0, long seconds=0, long minutes=0, long hours=0, int days=0)
| Set the value of the time interval. More...
void | RunContinuous (const PTimeInterval &time)
| Start a timer in continous cycle mode. More...
void | Stop (bool wait=true)
| Stop a running timer. More...
PBoolean | IsRunning () const
| Determine if the timer is currently running. More...
void | Pause ()
| Pause a running timer. More...
void | Resume ()
| Restart a paused timer continuing at the time it was paused. More...
PBoolean | IsPaused () const
| Determine if the timer is currently paused. More...
void | Reset ()
| Restart a timer continuing from the time it was initially. More...
const PTimeInterval & | GetResetTime () const
| Get the time this timer was set to initially. More...
const PNotifier & | GetNotifier () const
| Get the current call back function that is called whenever the timer expires. More...
void | SetNotifier (const PNotifier &func)
| Set the call back function that is called whenever the timer expires. More...
PInt64 | GetMilliSeconds () const
| Return number of milliseconds left in timer. More...
PInt64 | GetAbsoluteTime () const
| Return absolute time timer will expire. More...
Public Member Functions inherited from PTimeInterval
| PTimeInterval (PInt64 millisecs=0)
| Create a new time interval object. More...
| PTimeInterval (long millisecs, long seconds, long minutes=0, long hours=0, int days=0)
| PTimeInterval (const PString &str)
PObject * | Clone () const
| Create a new copy of the time interval. More...
virtual Comparison | Compare (const PObject &obj) const
| Rank the two time intervals. More...
virtual void | PrintOn (ostream &strm) const
| Output the time interval to the I/O stream. More...
virtual void | ReadFrom (istream &strm)
| Input the time interval from the I/O stream. More...
virtual void | SetMilliSeconds (PInt64 msecs)
| Set the number of milliseconds for the time interval. More...
long | GetSeconds () const
| Get the number of whole seconds for the time interval. More...
long | GetMinutes () const
| Get the number of whole minutes for the time interval. More...
int | GetHours () const
| Get the number of whole hours for the time interval. More...
int | GetDays () const
| Get the number of whole days for the time interval. More...
DWORD | GetInterval () const
| Get the number of milliseconds for the time interval. More...
PTimeInterval | operator- () const
| Unary minus, get negative of time interval. More...
PTimeInterval | operator+ (const PTimeInterval &interval) const
| Add the two time intervals yielding a third time interval. More...
PTimeInterval & | operator+= (const PTimeInterval &interval)
| Add the second time interval to the first time interval. More...
PTimeInterval | operator- (const PTimeInterval &interval) const
| Subtract the two time intervals yielding a third time interval. More...
PTimeInterval & | operator-= (const PTimeInterval &interval)
| Subtract the second time interval from the first time interval. More...
PTimeInterval | operator* (int factor) const
| Multiply the time interval by a factor yielding a third time interval. More...
PTimeInterval & | operator*= (int factor)
| Multiply the time interval by a factor. More...
int | operator/ (const PTimeInterval &smaller) const
| Divide the time interval by another interval yielding a count. More...
PTimeInterval | operator/ (int factor) const
| Divide the time interval by a factor yielding a third time interval. More...
PTimeInterval & | operator/= (int factor)
| Divide the time interval by a factor. More...
bool | operator== (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator== (long msecs) const
bool | operator!= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator!= (long msecs) const
bool | operator> (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator> (long msecs) const
bool | operator>= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator>= (long msecs) const
bool | operator< (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator< (long msecs) const
bool | operator<= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator<= (long msecs) const
PString | AsString (int decimals=3, Formats format=NormalFormat, int width=1) const
Public Member Functions inherited from PObject
unsigned | GetTraceContextIdentifier () const
| Get PTRACE context identifier. More...
void | SetTraceContextIdentifier (unsigned id)
void | GetTraceContextIdentifier (PObject &obj)
void | GetTraceContextIdentifier (PObject *obj)
void | SetTraceContextIdentifier (const PObject &obj)
void | SetTraceContextIdentifier (const PObject *obj)
virtual | ~PObject ()
template<class CLS >
CLS * | CloneAs () const
| As for Clone() but converts to specified type. More...
virtual PINDEX | HashFunction () const
| This function yields a hash value required by the `PDictionary` class. More...
virtual const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. More...
__inline const PObject * | PTraceObjectInstance () const
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const
| Determine the byte wise comparison of two objects. More...
bool | operator== (const PObject &obj) const
| Compare the two objects. More...
bool | operator!= (const PObject &obj) const
| Compare the two objects. More...
bool | operator< (const PObject &obj) const
| Compare the two objects. More...
bool | operator> (const PObject &obj) const
| Compare the two objects. More...
bool | operator<= (const PObject &obj) const
| Compare the two objects. More...
bool | operator>= (const PObject &obj) const
| Compare the two objects. More...
virtual void | PrintOn (ostream &strm) const
| Output the contents of the object to the stream. More...
virtual void | ReadFrom (istream &strm)
| Input the contents of the object from the stream. More...

## Protected Attributes
Pool_T & | m_pool

## Additional Inherited Members
Public Types inherited from PTimer
typedef unsigned | IDType
Static Public Member Functions inherited from PTimer
static PTimeInterval | Tick ()
| Get the number of milliseconds since some arbtrary point in time. More...
static unsigned | Resolution ()
| Get the smallest number of milliseconds that the timer can be set to. More...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...
Friends inherited from PObject

## Detailed Description

### template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>
class PPoolTimer< Work_T, Pool_T >

Template abstract class for a PTimer that queues a work item to a thread pool.

THis allows for load balancing of timer actions and, in complex muti-threading sytems, it is very easy for a deadlock to occur with the usual PNotifier method of executing a PTimer call back. This tries to largely avoid the issue by the housekeeper thread queuing a PThreadPool "work item" for later processing. The thread pooling system has a sophisticated system for avoiding deadlocks by making sure a particular target, indicated through a string "token", is always handled by the same thread.

Usage: class MyWork1 : public MyWork { MyWork1(int value); virtual void Work(); }; PPoolTimerArg1<MyWork1, int, MyWork> timer;

timer(threadPool, 27)

Note if more than three parameters are required for the Work class, then you will need to use a struct and PPoolTimerArg1<WorkLotsParams, ParamsStruct>

## Constructor & Destructor Documentation

template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>

PPoolTimer< Work_T, Pool_T >::PPoolTimer | ( | Pool_T & | pool | ) |
| inline

## Member Function Documentation

template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>

virtual Work_T* PPoolTimer< Work_T, Pool_T >::CreateWork | ( |  | ) |
| pure virtual

Implemented in PPoolTimerArg3< Work_T, Arg1, Arg2, Arg3, Base_T, Pool_T >, PPoolTimerArg2< Work_T, Arg1, Arg2, Base_T, Pool_T >, PPoolTimerArg1< Work_T, Arg1, Base_T, Pool_T >, and PPoolTimerArg0< Work_T, Base_T, Pool_T >.

Referenced by PPoolTimer< Base_T, Pool_T >::OnTimeout().

template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>

virtual const char* PPoolTimer< Work_T, Pool_T >::GetGroup | ( | const Work_T & |  | ) | const
| inline virtual

Referenced by PPoolTimer< Base_T, Pool_T >::OnTimeout().

template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>

virtual void PPoolTimer< Work_T, Pool_T >::OnTimeout | ( |  | ) |
| inline virtual

This function is called on time out.

That is when the system timer processing decrements the timer from a positive value to less than or equal to zero. The interval is then reset to zero and the function called.

Please note that the application should not execute large amounts of code in this call back or the accuracy of ALL timers can be severely impacted.

The default behaviour of this function is to call the `PNotifier` callback function.

Reimplemented from PTimer.

template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>

PPoolTimer< Work_T, Pool_T >::PTIMER_OPERATORS | ( | PPoolTimer< Work_T, Pool_T > |  | ) |

## Member Data Documentation

template<class Work_T, class Pool_T = PQueuedThreadPool<Work_T>>

Pool_T& PPoolTimer< Work_T, Pool_T >::m_pool
| protected

Referenced by PPoolTimer< Base_T, Pool_T >::OnTimeout().

The documentation for this class was generated from the following file:

- timer.h