cwidget
0.5.17
|
A simple unbounded communications channel suitable for use as, eg, an event queue. More...
#include <event_queue.h>
Public Member Functions | |
event_queue () | |
Create an empty queue. More... | |
void | put (const T &t) |
Push the given value onto the event queue. More... | |
T | get () |
Retrieve a single value from the event queue. More... | |
bool | try_get (T &out) |
Retrieve a single value from the event queue if the queue is non-empty. More... | |
bool | timed_get (T &out, const timespec &until) |
Retrieve a single value from the event queue, or fail if the time "until" is reached. | |
bool | empty () const |
Return true if the event queue is currently empty. More... | |
A simple unbounded communications channel suitable for use as, eg, an event queue.
Writers never block (except as necessary to maintain consistency), but readers block while the queue is empty. If there are multiple readers, they will receive results in an arbitrary order.
This implementation is safe and flexible, but not terribly efficient. For instance, readers and writers block each other out (other approaches can avoid this unless the queue is empty). In aptitude it's used for the global event queue, which doesn't get all that many deliveries, so it should be good enough. Just don't use it to stream bits off a network connection and then complain I didn't warn you!
|
inline |
Create an empty queue.
|
inline |
Return true if the event queue is currently empty.
|
inline |
Retrieve a single value from the event queue.
References cwidget::threads::condition::wait().
Referenced by cwidget::toplevel::mainloop().
|
inline |
Push the given value onto the event queue.
Referenced by cwidget::toplevel::post_event().
|
inline |
Retrieve a single value from the event queue if the queue is non-empty.
out | the location in which to store the retrieved value |
Referenced by cwidget::toplevel::mainloop(), cwidget::toplevel::poll(), and cwidget::toplevel::shutdown().