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

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

#include "TimerThread.hpp"
#include <assert.h>
+ Include dependency graph for TimerThread.cpp:

Go to the source code of this file.

Classes

struct  anonymous_namespace{TimerThread.cpp}::TimerEvent
 Structure to contain information for a timer event. More...
 

Macros

#define INVALID_EVENT_ID   (-10 & 1 << 29)
 Invalid event ID.
 

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.
 
Scope restricted to file
TimerEventanonymous_namespace{TimerThread.cpp}::CreateTimerEvent (TimerThread *timer, ThreadPoolJob *job, Duration persistent, time_t eventTime, int id)
 Creates a Timer Event.
 
void anonymous_namespace{TimerThread.cpp}::FreeTimerEvent (TimerThread *timer, TimerEvent *event)
 Deallocates a dynamically allocated TimerEvent.
 
void anonymous_namespace{TimerThread.cpp}::TimerThreadWorker (void *arg)
 Implements timer thread.
 
int anonymous_namespace{TimerThread.cpp}::CalculateEventTime (time_t *timeout, TimeoutType type)
 Calculates the appropriate timeout in absolute seconds since Jan 1, 1970.
 

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


Class Documentation

◆ anonymous_namespace{TimerThread.cpp}::TimerEvent

struct anonymous_namespace{TimerThread.cpp}::TimerEvent

Structure to contain information for a timer event.

Internal to the TimerThread.

Definition at line 58 of file TimerThread.cpp.

+ Collaboration diagram for anonymous_namespace{TimerThread.cpp}::TimerEvent:
Class Members
ThreadPoolJob job
time_t eventTime

Absolute time for event in seconds since Jan 1, 1970.

Duration persistent

Long term or short term job.

int id

Id of timer event. (can be null?).

Macro Definition Documentation

◆ INVALID_EVENT_ID

#define INVALID_EVENT_ID   (-10 & 1 << 29)

Invalid event ID.

Definition at line 49 of file TimerThread.cpp.

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: