UCommon
|
Event notification to manage scheduled realtime threads. More...
#include <thread.h>
Public Member Functions | |
void | reset (void) |
Reset triggered conditional. | |
void | signal (void) |
Signal pending event. More... | |
TimedEvent (void) | |
Create event handler and timer for timing of events. | |
TimedEvent (timeout_t timeout) | |
Create event handler and timer set to trigger a timeout. More... | |
TimedEvent (time_t timeout) | |
Create event handler and timer set to trigger a timeout. More... | |
bool | wait (timeout_t timeout) |
Wait to be signalled or until timer expires. More... | |
void | wait (void) |
A simple wait until triggered. | |
~TimedEvent () | |
Destroy timer and release pending events. | |
![]() | |
void | clear (void) |
Clear pending timer, has no value. | |
timeout_t | get (void) const |
Get remaining time until the timer expires. More... | |
timeout_t | operator * () const |
Get remaining time until timer expires by reference. More... | |
operator bool () const | |
Check if timer expired for is() expression. More... | |
bool | operator! () const |
Check if timer has expired. More... | |
bool | operator!= (const Timer &timer) const |
Compare timers if not same timeout. More... | |
Timer & | operator+= (time_t expire) |
Adjust timer expiration. More... | |
Timer & | operator+= (timeout_t expire) |
Adjust timer expiration. More... | |
timeout_t | operator- (const Timer &timer) |
Compute difference between two timers. More... | |
Timer & | operator-= (time_t expire) |
Adjust timer expiration. More... | |
Timer & | operator-= (timeout_t expire) |
Adjust timer expiration. More... | |
bool | operator< (const Timer &timer) const |
Compare timers if earlier timeout than another timer. More... | |
bool | operator<= (const Timer &timer) const |
Compare timers if earlier than or equal to another timer. More... | |
Timer & | operator= (time_t expire) |
Set timer expiration. More... | |
Timer & | operator= (timeout_t expire) |
Set timer expiration. More... | |
bool | operator== (const Timer &timer) const |
Compare timers if same timeout. More... | |
bool | operator> (const Timer &timer) const |
Compare timers if later timeout than another timer. More... | |
bool | operator>= (const Timer &timer) const |
Compare timers if later than or equal to another timer. More... | |
void | set (timeout_t expire) |
Set the timer to expire. More... | |
void | set (time_t expire) |
Set the timer to expire. More... | |
void | set (void) |
Set (update) the timer with current time. | |
Timer () | |
Construct an untriggered timer set to the time of creation. | |
Timer (timeout_t offset) | |
Construct a triggered timer that expires at specified offset. More... | |
Timer (time_t offset) | |
Construct a triggered timer that expires at specified offset. More... | |
Timer (const Timer ©) | |
Construct a timer from a copy of another timer. More... | |
Protected Member Functions | |
void | lock (void) |
Lock the object for wait or to manipulate derived data. More... | |
void | release (void) |
Release the object lock after waiting. More... | |
bool | sync (void) |
Wait while locked. More... | |
![]() | |
bool | is_active (void) const |
Check if timer active. More... | |
bool | update (void) |
Check if timer has been updated since last check. More... | |
Additional Inherited Members | |
![]() | |
typedef uint64_t | tick_t |
![]() | |
static void | sync (Timer &timer) |
Sleep current thread until the specified timer expires. More... | |
static tick_t | ticks (void) |
Get timer ticks since uuid epoch. More... | |
![]() | |
static const timeout_t | inf = ((timeout_t)(-1)) |
static const time_t | reset = ((time_t)(0)) |
Event notification to manage scheduled realtime threads.
The timer is advanced to sleep threads which then wakeup either when the timer has expired or they are notified through the signal handler. This can be used to schedule and signal one-time completion handlers or for time synchronized events signaled by an asychrononous I/O or event source.
ucommon::TimedEvent::TimedEvent | ( | timeout_t | timeout | ) |
Create event handler and timer set to trigger a timeout.
timeout | in milliseconds. |
ucommon::TimedEvent::TimedEvent | ( | time_t | timeout | ) |
Create event handler and timer set to trigger a timeout.
timeout | in seconds. |
|
protected |
Lock the object for wait or to manipulate derived data.
This is relevant to manipulations in a derived class.
|
protected |
Release the object lock after waiting.
This is relevent to manipulations in a derived class.
void ucommon::TimedEvent::signal | ( | void | ) |
Signal pending event.
Object may be locked or unlocked. The signalling thread may choose to lock and check a condition in a derived class before signalling.
|
protected |
Wait while locked.
This can be used in more complex derived objects where we are concerned with synchronized access between the signaling and event thread. This can be used in place of wait, but lock and release methods must be used around it.
bool ucommon::TimedEvent::wait | ( | timeout_t | timeout | ) |
Wait to be signalled or until timer expires.
This is a wrapper for expire for simple completion events.
timeout | to wait from last reset. |