Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
|
Class allowing to sleep until one out of multiple i/o operations becomes possible.
This class serves as an interface to the 'select' system call. Furthermore, it helps to implement worker threads that (may) monitor files and receive commands (events) with the help of a self-pipe.
#include "base.H"
Public Member Functions | |
Enable the command mechanism ... | |
void | EnableCmds (int _cmdRecSize) |
Enable sending commands by PutCmd(). To be called immediately after initialization and only if the command feature is used. | |
For the sleeping thread: Preparation... | |
These methods must be called before each invocation of Sleep(). | |
void | Prepare () |
Prepare for sleeping, clear all file descriptors. | |
void | AddReadable (int fd) |
Add file descriptor fd to monitor for readability, descriptors < 0 are silently ignored. | |
void | AddWritable (int fd) |
Add file descriptor fd to monitor for writability, descriptors < 0 are silently ignored. | |
For the sleeping thread: Sleep... | |
void | Sleep (TTicks maxTime=-1) |
Sleep until one file descriptor is readable/writable or a new command was received. More... | |
For the sleeping thread: Afterwards... | |
bool | IsReadable (int fd) |
Check if file descriptor is readable (flags are only updated in Sleep() ). | |
bool | IsWritable (int fd) |
Check if file descriptor is writable (flags are only updated in Sleep() ). | |
bool | GetCmd (void *retCmdRec) |
Get and consume next command (non-blocking). More... | |
For other threads... | |
void | PutCmd (const void *cmdRec, TTicks t=0, TTicks _interval=0) |
Send message to sleeper. More... | |
void | ClearTimedCmds () |
Clear any scheduled commands which have not yet been put into the queue. Note: Respective commands may still be in the queue and returned by GetCmd() after calling this! | |
void CSleeper::Sleep | ( | TTicks | maxTime = -1 | ) |
Sleep until one file descriptor is readable/writable or a new command was received.
maxTime | Maximum waiting time; -1: wait forever, 0 => do not wait |
A non-blocking Sleep() (maxTime
== 0) updates the internal readability/writability flags.
bool CSleeper::GetCmd | ( | void * | retCmdRec | ) |
Get and consume next command (non-blocking).
Send message to sleeper.
cmd == NULL
represents "no command" and will be ignored by receiver. The command can optionally be scheduled for a certain time or even be repeated. t
is an absolute time, t == 0
represents "now".