My Project
Public Types | Public Member Functions | Protected Types | Protected Attributes | List of all members
ParaEngine::concurrent_queue< Data > Class Template Reference

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
 

Detailed Description

template<typename Data>
class ParaEngine::concurrent_queue< Data >

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.

Member Function Documentation

§ push()

template<typename Data >
void ParaEngine::concurrent_queue< Data >::push ( value_type &  data)
inline

add a data item to the back of the queue.

if buffer is full, the more recent messages remain in the queue.

§ push_front()

template<typename Data >
void ParaEngine::concurrent_queue< Data >::push_front ( value_type &  data)
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.

§ SetUseEvent()

template<typename Data >
void ParaEngine::concurrent_queue< Data >::SetUseEvent ( bool  bUseEvent)
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.

§ try_push()

template<typename Data >
BufferStatus ParaEngine::concurrent_queue< Data >::try_push ( value_type &  item)
inline

try push to back of the queue.

Parameters
itemthe object to add
Returns
: return buffer status after the item is added. If BufferOverFlow, it means adding is failed; if BufferFirst, this is the first item added. if BufferFull, the buffer is full after inserting the new one, in other cases, BufferNormal is returned.
Note
: thread safe

Member Data Documentation

§ m_use_event

template<typename Data >
bool ParaEngine::concurrent_queue< Data >::m_use_event
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.


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