#include <circularbuffer.h>
Public Member Functions | |
CCircularBuffer (size_t queueSize) | |
Default constructor which builds an empty buffer. | |
~CCircularBuffer () | |
D'tor that cleans up the allocated buffer space. | |
bool | isBroken () |
Test if broken (for timeouts/polling and use of Break). | |
void | Break () |
Cause any threads blocked on the getElement and putElement functions to return immediately. | |
void | ResetBreak () |
Reset the shutdown event; subsequent calls to getElement or putElement may block if the buffer is empty or full respectively. | |
bool | putElement (const T &el, DWORD nTimeout=INFINITE) |
Enter a data item into the buffer. | |
bool | getElement (T &el, DWORD nTimeout=INFINITE) |
Consume a data item from the buffer. |
|
Default constructor which builds an empty buffer. Note: the space for the items is allocated here, in advance, on the heap. Circular buffers are generally used for communication between high priority and low priority threads (for example, for a log). In this case, we don't want the high priority thread to block on anything, including memory allocation; hence the advance allocation. Thus, if you are storing large objects in the buffer, consider storing pointers to them to save the copies/excessive memory consumption that may otherwise be caused. |
|
Cause any threads blocked on the getElement and putElement functions to return immediately. This is generally useful when you are shutting down an application and your worker threads are blocked on getElement() or putElement(). These functions will return false indicating that no data was placed into the buffer or consumed from it. |
|
Consume a data item from the buffer.
|
|
Enter a data item into the buffer.
|
|
Reset the shutdown event; subsequent calls to getElement or putElement may block if the buffer is empty or full respectively. This can be used after an aborted shutdown. |