My Project
|
it implements a producer/consumer(s) queue design pattern. More...
#include <ParaRingBuffer.h>
Public Types | |
enum | BufferStatus { BufferOverFlow = 0, BufferFull = 1, BufferNormal = 2, BufferEmpty = 3, BufferFirst = 3 } |
Public Member Functions | |
concurrent_queue (size_type capacity) | |
void | SetUseEvent (bool bUseEvent) |
whether to use event to inform consumer when new data items are added to the queue. More... | |
BufferStatus | try_push (value_type &item) |
try push to back of the queue. More... | |
void | push (value_type &data) |
add a data item to the back of the queue. More... | |
void | push_front (value_type &data) |
add a data item to the front of the queue. More... | |
bool | empty () const |
bool | try_pop (value_type &popped_value) |
void | wait_and_pop (value_type &popped_value) |
Protected Types | |
typedef boost::circular_buffer< Data > | container_type |
typedef container_type::size_type | size_type |
typedef container_type::value_type | value_type |
Protected Attributes | |
boost::mutex | m_mutex |
boost::condition_variable | m_condition_variable |
bool | m_use_event |
whether to use event to inform consumer when new data items are added to the queue. More... | |
container_type | m_container |
it implements a producer/consumer(s) queue design pattern.
One or more producers push(data) to the queue, and multiple consumers wait_and_pop(data) from the queue. Internally a fixed-sized ring buffer is used. if buffer is full, older messages are dropped without notification. all functions are thread-safe.
|
inline |
add a data item to the back of the queue.
if buffer is full, the more recent messages remain in the queue.
|
inline |
add a data item to the front of the queue.
This ensures that message is always added even queue is full, where the recent message are dropped. This function is only used to insert high priority command, otherwise use push() function instead.
|
inline |
whether to use event to inform consumer when new data items are added to the queue.
Default to true. if one uses polling,such as in the main game thread, there is no need to enable use_event. when enabled, there is a performance hit.
|
inline |
try push to back of the queue.
item | the object to add |
|
protected |
whether to use event to inform consumer when new data items are added to the queue.
Default to true. if one uses polling,such as in the main game thread, there is no need to enable use_event. when enabled, there is a performance hit.