Manage threads that start at a given time (for internal use only). More...
#include "ThreadPool.hpp"
Go to the source code of this file.
Classes | |
struct | TimerThread |
A timer thread that allows the scheduling of a job to run at a specified time in the future. More... | |
Enumerations | |
enum | TimeoutType { ABS_SEC , REL_SEC } |
Timeout Types. More... | |
Functions | |
int | TimerThreadInit (TimerThread *timer, ThreadPool *tp) |
Initializes and starts timer thread. | |
int | TimerThreadSchedule (TimerThread *timer, time_t timeout, TimeoutType type, ThreadPoolJob *job, Duration duration, int *id) |
Schedules an event to run at a specified time. | |
int | TimerThreadRemove (TimerThread *timer, int id, ThreadPoolJob *out) |
Removes an event from the timer Q. | |
int | TimerThreadShutdown (TimerThread *timer) |
Shutdown the timer thread. | |
Manage threads that start at a given time (for internal use only).
Because this is for internal use, parameters are NOT checked for validity. The caller must ensure valid parameters.
Definition in file TimerThread.hpp.
struct TimerThread |
A timer thread that allows the scheduling of a job to run at a specified time in the future.
Because the timer thread uses the thread pool there is no gurantee of timing, only approximate timing.
Uses ThreadPool, Mutex, Condition, Thread.
Definition at line 61 of file TimerThread.hpp.
Class Members | ||
---|---|---|
pthread_mutex_t | mutex | [in] |
pthread_cond_t | condition | [in] |
int | lastEventId | [in] |
LinkedList | eventQ | [in] |
int | shutdown | [in] |
FreeList | freeEvents | [in] |
ThreadPool * | tp | [in] |
enum TimeoutType |
Timeout Types.
Enumerator | |
---|---|
ABS_SEC | seconds from Jan 1, 1970. |
REL_SEC | seconds from current time. |
Definition at line 47 of file TimerThread.hpp.
int TimerThreadInit | ( | TimerThread * | timer, |
ThreadPool * | tp | ||
) |
Initializes and starts timer thread.
[in] | timer | Valid timer thread pointer. |
[in] | tp | Valid thread pool to use. Must be started. Must be valid for lifetime of timer. Timer must be shutdown BEFORE thread pool. |
Definition at line 221 of file TimerThread.cpp.
int TimerThreadSchedule | ( | TimerThread * | timer, |
time_t | timeout, | ||
TimeoutType | type, | ||
ThreadPoolJob * | job, | ||
Duration | duration, | ||
int * | id | ||
) |
Schedules an event to run at a specified time.
[in] | timer | Valid timer thread pointer. |
[in] | timeout | time of event. Either in absolute seconds, or relative seconds in the future. |
[in] | type | either ABS_SEC, or REL_SEC. If REL_SEC, then the event will be scheduled at the current time + REL_SEC. |
[in] | job | Valid Thread pool job with following fields. |
[in] | duration | |
[out] | id | Id of timer event. (can be null). |
Definition at line 276 of file TimerThread.cpp.
int TimerThreadRemove | ( | TimerThread * | timer, |
int | id, | ||
ThreadPoolJob * | out | ||
) |
Removes an event from the timer Q.
Events can only be removed before they have been placed in the thread pool.
[in] | timer | Valid timer thread pointer. |
[in] | id | Id of event to remove. |
[out] | out | Thread pool job. |
Definition at line 339 of file TimerThread.cpp.
int TimerThreadShutdown | ( | TimerThread * | timer | ) |
Shutdown the timer thread.
Events scheduled in the future will NOT be run. Timer thread should be shutdown BEFORE it's associated thread pool.
[in] | timer | Valid timer thread pointer. |
Definition at line 372 of file TimerThread.cpp.