Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
OSSelectWakeup Class Reference

Helper class that allows a select to be asynchronously woken up. More...

#include <OSSelectWakeup.hxx>

Inheritance diagram for OSSelectWakeup:
Atomic

Public Member Functions

os_thread_t main_thread ()
 
void lock_to_thread ()
 Prepares the current thread for asynchronous wakeups.
 
void wakeup ()
 Wakes up the select in the locked thread.
 
void clear_wakeup ()
 Called from the main thread after being woken up.
 
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long deadline_nsec)
 Portable call to a select that can be woken up asynchronously from a different thread or an ISR context.
 

Private Attributes

bool pendingWakeup_
 True if there was a wakeup call since the previous select finished.
 
bool inSelect_
 True during the duration of a select operation.
 
os_thread_t thread_
 ID of the main thread we are engaged upon.
 

Additional Inherited Members

- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Detailed Description

Helper class that allows a select to be asynchronously woken up.

Definition at line 75 of file OSSelectWakeup.hxx.

Constructor & Destructor Documentation

◆ OSSelectWakeup()

OSSelectWakeup::OSSelectWakeup ( )
inline

Definition at line 78 of file OSSelectWakeup.hxx.

◆ ~OSSelectWakeup()

OSSelectWakeup::~OSSelectWakeup ( )
inline

Definition at line 84 of file OSSelectWakeup.hxx.

Member Function Documentation

◆ clear_wakeup()

void OSSelectWakeup::clear_wakeup ( )
inline

Called from the main thread after being woken up.

Enables further wakeup signals to be collected.

Definition at line 154 of file OSSelectWakeup.hxx.

◆ lock_to_thread()

void OSSelectWakeup::lock_to_thread ( )
inline

Prepares the current thread for asynchronous wakeups.

Can be called only once.

Definition at line 99 of file OSSelectWakeup.hxx.

◆ main_thread()

os_thread_t OSSelectWakeup::main_thread ( )
inline
Returns
the thread ID that we are engaged upon.

Definition at line 92 of file OSSelectWakeup.hxx.

◆ select()

int OSSelectWakeup::select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
long long  deadline_nsec 
)

Portable call to a select that can be woken up asynchronously from a different thread or an ISR context.

Parameters
nfdsis as a regular select call.
readfdsis as a regular select call.
writefdsis as a regular select call.
exceptfdsis as a regular select call.
deadline_nsecis the maximum time to sleep if no fd activity and no wakeup happens. -1 to sleep indefinitely, 0 to return immediately.
Returns
what select would return (number of live FDs, 0 in case of timeout), or -1 and errno==EINTR if the select was woken up asynchronously

Definition at line 44 of file OSSelectWakeup.cxx.

◆ wakeup()

void OSSelectWakeup::wakeup ( )
inline

Wakes up the select in the locked thread.

Definition at line 124 of file OSSelectWakeup.hxx.

Member Data Documentation

◆ inSelect_

bool OSSelectWakeup::inSelect_
private

True during the duration of a select operation.

Definition at line 241 of file OSSelectWakeup.hxx.

◆ pendingWakeup_

bool OSSelectWakeup::pendingWakeup_
private

True if there was a wakeup call since the previous select finished.

Definition at line 239 of file OSSelectWakeup.hxx.

◆ thread_

os_thread_t OSSelectWakeup::thread_
private

ID of the main thread we are engaged upon.

Definition at line 243 of file OSSelectWakeup.hxx.


The documentation for this class was generated from the following files: