scclib
Stable Cloud Computing C++ Library
|
Signaling kernel event counter. More...
#include <event.h>
Public Types | |
enum | EventFlag { nonblocking = 1 , semaphore = 2 } |
Event flags. More... | |
Public Member Functions | |
Event (int=0) | |
Construct an event. More... | |
Event (const Event &)=delete | |
No copy. | |
void | operator= (const Event &)=delete |
No copy. | |
Event (Event &&other) | |
Move constructor. | |
const Event & | operator= (Event &&other) |
Move assignment. | |
operator int () const | |
Cast object to int. | |
int | fd () const |
Return file descriptor. More... | |
void | reset (int=-1) |
Reset the event. More... | |
uint64_t | read () |
Read from (decrement) the event counter. More... | |
void | write (uint64_t) |
Write to (increment) the event counter. More... | |
Signaling kernel event counter.
Writes increment the event counter.
Sempahore mode means reads will decrement the counter by 1. Otherwise, reads reset the counter to 0.
Non-blocking mode means the event can throw an exception (EAGAIN) if called when not signalled. The event should probably be polled in this case. See: Kernel file descriptor event notification poller
Event::Event | ( | int | flags = 0 | ) |
|
inline |
uint64_t Event::read | ( | ) |
Read from (decrement) the event counter.
For blocking event, blocks until counter becomes signalled (non-zero). For a non-blocking event, throws an exception if the counter is not signalled.
For a semaphore, returns 1 and decrements counter by 1. Otherwise, returns the counter value and sets counter to 0.
void Event::reset | ( | int | flags = -1 | ) |
Reset the event.
Reset the event to unsignalled state (counter 0).
flags | if >= 0, override the event flags, otherwise, reset to original flags. See: EventFlag |
void Event::write | ( | uint64_t | v | ) |
Write to (increment) the event counter.
v | Increments the event counter by the value. |