This class provides a thread aware fifo queue for Data objects, providing memory management for all Data object pointers it contains. More...
#include <dataqueue.h>
Public Member Functions | |
void | push (Data *data) |
Pushes data into the end of the queue. | |
Data * | pop () |
Pops the next element off the front of the queue. | |
Data * | wait_pop (int timeout=-1) |
Pops the next element off the front of the queue, and waits until one exists if empty. | |
void | append_from (DataQueue &other) |
Pops all data from other and appends it to this. | |
bool | empty () const |
Returns true if the queue is empty. | |
size_t | size () const |
Returns number of items in the queue. |
This class provides a thread aware fifo queue for Data objects, providing memory management for all Data object pointers it contains.
It uses similar member names as std::queue<>, for consistency.
Definition at line 40 of file dataqueue.h.
void Barry::DataQueue::append_from | ( | DataQueue & | other | ) |
Pops all data from other and appends it to this.
After calling this function, other will be empty, and this will contain all its data.
In the case of an exception, any uncopied data will remain in other.
This is a locking optimization, so all copying can happen inside one lock, instead of locking for each copy.
Definition at line 175 of file dataqueue.cc.
Referenced by Barry::SocketRoutingQueue::UnregisterInterest().
bool Barry::DataQueue::empty | ( | ) | const |
Returns true if the queue is empty.
Definition at line 194 of file dataqueue.cc.
Data * Barry::DataQueue::pop | ( | ) |
Pops the next element off the front of the queue.
Returns 0 if empty. The queue no longer owns this pointer upon return.
Definition at line 85 of file dataqueue.cc.
Referenced by Barry::SocketRoutingQueue::DoRead().
void Barry::DataQueue::push | ( | Data * | data | ) |
Pushes data into the end of the queue.
The queue owns this pointer as soon as the function is called. In the case of an exception, it will be freed. Performs a thread broadcast once new data has been added.
Definition at line 58 of file dataqueue.cc.
Referenced by Barry::SocketRoutingQueue::AllocateBuffers(), Barry::SocketRoutingQueue::DoRead(), and Barry::SocketRoutingQueue::ReturnBuffer().
size_t Barry::DataQueue::size | ( | ) | const |
Returns number of items in the queue.
Definition at line 205 of file dataqueue.cc.
Referenced by Barry::SocketRoutingQueue::AllocateBuffers(), and wait_pop().
Data * Barry::DataQueue::wait_pop | ( | int | timeout = -1 |
) |
Pops the next element off the front of the queue, and waits until one exists if empty.
If still no data on timeout, returns null. (unlock the access mutex while waiting!)
Timeout specified in milliseconds. Default is wait forever.
Definition at line 107 of file dataqueue.cc.
References size(), and Barry::ThreadTimeout().
Referenced by Barry::SocketRoutingQueue::DefaultRead(), and Barry::SocketRoutingQueue::SocketRead().