CRingBuffer Class Reference
A thread-safe circular buffer with multiple readers and multiple writers.
More...
#include <RingBuffer.h>
List of all members.
Signals
Public Member Functions
Detailed Description
A thread-safe circular buffer with multiple readers and multiple writers.
A ringbuffer is a FIFO buffer: First In, First Out. It gets its name because if data is to be written beyond the end of the internal buffer, it wraps around to the beginning (provided that there is enough space left and we don't overwrite the tail). Thus the buffer is used 'circular', in a ring.
What makes this class special is that it supports multiple writers and readers, and is thread-safe. So, multiple threads can write to the buffer (appending at the front), and multiple threads can read from the tail. (Please note that the readers and writers themselves are not thread safe! Use separate readers and writers in different threads).
However, the functionality is not symmetrical: there is only a single head pointer, so every writer always appends to the buffer, not overwriting anything. But each reader has its own tail pointer and all readers will receive the same data from the buffer. Effectively, the data is copied to the various reader threads.
The readers don't have a head pointer; just a tail and the length; the length is increased every time data is added by a writer. The tail and length are updated at read operations.
Note: you must use at least Qt 2.3.0, because there was a bug in the QMutex class.
Constructor & Destructor Documentation
CRingBuffer::CRingBuffer |
( |
unsigned int |
buffer_space |
) |
|
|
|
- Parameters:
-
| buffer_space | The desired buffer length, in bytes |
Constructor; allocates space. |
Member Function Documentation
void CRingBuffer::BufferFlushed |
( |
|
) |
[signal] |
|
unsigned int CRingBuffer::GetBufferLength |
( |
|
) |
|
|
void CRingBuffer::ReaderAttached |
( |
|
) |
[signal] |
|
void CRingBuffer::ReaderDetached |
( |
|
) |
[signal] |
|
void CRingBuffer::WriterAttached |
( |
|
) |
[signal] |
|
void CRingBuffer::WriterDetached |
( |
|
) |
[signal] |
|
The documentation for this class was generated from the following files:
Generated on Wed Dec 13 23:38:47 2006 for CamStream by
1.3.7