|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Multiplexing timer: schedule many periodic timers and consume their expiries from one queue. More...
#include <Utils.h>
Public Member Functions | |
| Timer () | |
| ~Timer () | |
| bool | addTimer (uint32 id, uint32 interval, uint64 start=0, uint64 end=0) |
| Register a periodic timer. | |
| bool | triggerTimer (uint32 id) |
Manually inject an expiry for timer id, as if it had fired now. | |
| bool | waitForTimer (uint32 timeout, uint32 &id, uint64 &time) |
| Wait for the next expiry of any registered timer. | |
| bool | removeTimer (uint32 id) |
| Unregister a timer and cancel its OS timer. | |
Static Public Attributes | |
| static std::map< uint32, Timer * > * | timers = NULL |
| Global registry mapping globalID to live Timer instances, used by the OS callbacks. | |
Multiplexing timer: schedule many periodic timers and consume their expiries from one queue.
Each addTimer() registers an OS timer (timer queue / dispatch source / POSIX timer). Expiries are pushed into an internal trigger queue which a consumer drains via waitForTimer(), giving a select()-like wait over any number of timers from a single thread.
| cmlabs::utils::Timer::Timer | ( | ) |
| cmlabs::utils::Timer::~Timer | ( | ) |
Definition at line 1651 of file Utils.cpp.
References removeTimer(), and timers.
| bool cmlabs::utils::Timer::addTimer | ( | uint32 | id, |
| uint32 | interval, | ||
| uint64 | start = 0, | ||
| uint64 | end = 0 ) |
Register a periodic timer.
| id | Caller-chosen id reported back by waitForTimer(). |
| interval | Period in milliseconds. |
| start | Optional absolute start time (ms epoch); 0 = now. |
| end | Optional absolute end time after which the timer stops; 0 = never. |
Definition at line 1672 of file Utils.cpp.
References cmlabs::utils::TimerSchedule::end, cmlabs::GetTimeNow(), cmlabs::utils::TimerSchedule::globalID, cmlabs::utils::TimerSchedule::handle, cmlabs::utils::TimerSchedule::id, cmlabs::utils::TimerSchedule::interval, cmlabs::utils::TimerSchedule::start, Timer(), cmlabs::utils::TimerCallback(), timers, and triggerTimer().
Referenced by cmlabs::utils::UnitTest_Timer().
| bool cmlabs::utils::Timer::removeTimer | ( | uint32 | id | ) |
Unregister a timer and cancel its OS timer.
| id | Timer id. |
Definition at line 1769 of file Utils.cpp.
References cmlabs::utils::TimerSchedule::handle.
Referenced by triggerTimer(), and ~Timer().
| bool cmlabs::utils::Timer::triggerTimer | ( | uint32 | id | ) |
Manually inject an expiry for timer id, as if it had fired now.
Definition at line 1796 of file Utils.cpp.
References cmlabs::utils::TimerSchedule::end, cmlabs::GetTimeNow(), cmlabs::utils::TimerSchedule::id, cmlabs::utils::TimerTrigger::id, cmlabs::utils::TimerSchedule::interval, removeTimer(), and cmlabs::utils::TimerTrigger::time.
Referenced by addTimer(), and cmlabs::utils::TimerCallback().
| bool cmlabs::utils::Timer::waitForTimer | ( | uint32 | timeout, |
| uint32 & | id, | ||
| uint64 & | time ) |
Wait for the next expiry of any registered timer.
| timeout | Max wait in milliseconds. | |
| [out] | id | Receives the id of the timer that fired. |
| [out] | time | Receives the expiry timestamp (ms). |
Definition at line 1818 of file Utils.cpp.
References cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), cmlabs::utils::TimerTrigger::id, and cmlabs::utils::TimerTrigger::time.
Referenced by cmlabs::utils::UnitTest_Timer().
|
static |
Global registry mapping globalID to live Timer instances, used by the OS callbacks.
Definition at line 646 of file Utils.h.
Referenced by addTimer(), cmlabs::ClearUtilsMaps(), Timer(), cmlabs::utils::TimerCallback(), and ~Timer().