CParaRingBuffer is normally used in a producer-consumer mode when producer threads produce items and store them in the container and consumer threads remove these items and process them.
More...
#include <ParaRingBuffer.h>
|
enum | BufferStatus {
BufferOverFlow = 0,
BufferFull = 1,
BufferNormal = 2,
BufferEmpty = 3,
BufferFirst = 3
} |
|
typedef boost::circular_buffer< T > | container_type |
|
typedef container_type::size_type | size_type |
|
typedef container_type::value_type | value_type |
|
|
| CParaRingBuffer (size_type capacity) |
|
BufferStatus | try_push (const value_type &item) |
| try push to back of the queue. More...
|
|
BufferStatus | try_push_get_front (const value_type &item, value_type **ppFrontItem) |
| same as try_push, except that it also returns pointer to the front object. More...
|
|
void | push_front (const value_type &item) |
| push to the front of the queue. More...
|
|
BufferStatus | try_push_array (const value_type *pItems, int nCount) |
| try push to back of the queue. More...
|
|
value_type * | try_front () |
|
bool | try_pop (value_type &item) |
| try pop from the front of the queue. More...
|
|
bool | try_next (value_type **ppItem) |
| try pop from the front of the queue and return the front object after the pop. More...
|
|
size_type | size () const |
|
bool | empty () const |
|
bool | full () const |
|
|
container_type | m_container |
|
mutex | m_mutex |
|
template<class T>
class ParaEngine::CParaRingBuffer< T >
CParaRingBuffer is normally used in a producer-consumer mode when producer threads produce items and store them in the container and consumer threads remove these items and process them.
The bounded buffer has to guarantee that producers do not insert items into the container when the container is full, that consumers do not try to remove items when the container is empty, and that each produced item is consumed by exactly one consumer.
- Note
- : most functions are thread-safe, a light mutex is used in place.
§ push_front()
push to the front of the queue.
this is usually for high priority messages. If queue is full, the last one will be removed.
- Parameters
-
- Note
- : thread safe
§ try_front()
- Returns
- : get a pointer to the front object if exist, or NULL.
- Note
- this is thread safe, however the returned object may be invalid if it is pop when you use it.
§ try_next()
try pop from the front of the queue and return the front object after the pop.
- Parameters
-
ppValueFront | get a pointer to the front object after the operation. |
- Returns
- : return true if succeed, false if queue is empty.
- Note
- : thread safe
§ try_pop()
try pop from the front of the queue.
- Parameters
-
ppValueFront | get a pointer to the front object after the operation. |
- Returns
- : return true if succeed, false if queue is empty.
- Note
- : thread safe
§ try_push()
try push to back of the queue.
- Parameters
-
- 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
§ try_push_array()
try push to back of the queue.
- 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
§ try_push_get_front()
same as try_push, except that it also returns pointer to the front object.
- Parameters
-
ppFrontItem | there is no guarantee that the front object pointer is valid after return. please ensure no other thread is popping items when you are accessing the front item. |
The documentation for this class was generated from the following file: