UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
TimerThread.hpp File Reference

Manage threads that start at a given time (for internal use only). More...

#include "ThreadPool.hpp"
+ Include dependency graph for TimerThread.hpp:
+ This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

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.


Class Documentation

◆ TimerThread

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.

+ Collaboration diagram for TimerThread:
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]

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ TimerThreadInit()

int TimerThreadInit ( TimerThread timer,
ThreadPool tp 
)

Initializes and starts timer thread.

Returns
On success: 0
On error: nonzero, returns error from ThreadPoolAddPersistent().
Parameters
[in]timerValid timer thread pointer.
[in]tpValid 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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TimerThreadSchedule()

int TimerThreadSchedule ( TimerThread timer,
time_t  timeout,
TimeoutType  type,
ThreadPoolJob job,
Duration  duration,
int *  id 
)

Schedules an event to run at a specified time.

Returns
On success: 0
On error: nonzero
  • EOUTOFMEM if not enough memory to schedule job.
Parameters
[in]timerValid timer thread pointer.
[in]timeouttime of event. Either in absolute seconds, or relative seconds in the future.
[in]typeeither ABS_SEC, or REL_SEC. If REL_SEC, then the event will be scheduled at the current time + REL_SEC.
[in]jobValid Thread pool job with following fields.
[in]duration
[out]idId of timer event. (can be null).

Definition at line 276 of file TimerThread.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TimerThreadRemove()

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.

Returns
On success: 0
On error: INVALID_EVENT_ID
Parameters
[in]timerValid timer thread pointer.
[in]idId of event to remove.
[out]outThread pool job.

Definition at line 339 of file TimerThread.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TimerThreadShutdown()

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.

Returns
Always 0
Parameters
[in]timerValid timer thread pointer.

Definition at line 372 of file TimerThread.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: