|
Miosix
2.0alpha1
|
#include <queue.h>
Public Member Functions | |
| BufferQueue () | |
| bool | isEmpty () const |
| bool | isFull () const |
| unsigned int | bufferMaxSize () const |
| unsigned int | numberOfBuffers () const |
| bool | tryGetWritableBuffer (T *&buffer) |
| void | bufferFilled (unsigned int actualSize) |
| unsigned char | availableForWriting () const |
| bool | tryGetReadableBuffer (const T *&buffer, unsigned int &actualSize) |
| void | bufferEmptied () |
| unsigned char | availableForReading () const |
| void | reset () |
A class to handle double buffering, but also triple buffering and in general N-buffering. Works between two threads but is especially suited to synchronize between a thread and an interrupt routine.
Note that unlike Queue, this class is only a data structure and not a synchronization primitive. The synchronization between the thread and the IRQ (or the other thread) must be done by the caller.
The internal implementation treats the buffers as a circular queue of N elements, hence the name.
| T | type of elements of the buffer, usually char or unsigned char |
| size | maximum size of a buffer |
| numbuf | number of buffers, the default is two resulting in a double buffering scheme. Values 0 and 1 are forbidden |
|
inline |
Constructor, all buffers are empty
|
inline |
|
inline |
|
inline |
After having called tryGetReadableBuffer() to retrieve a buffer and having read it, this member function allows to mark the buffer as available on the writer side.
|
inline |
After having called tryGetWritableBuffer() to retrieve a buffer and having filled it, this member function allows to mark the buffer as available on the reader side.
| actualSize | actual size of buffer. It usually equals bufferMaxSize but can be a lower value in case there is less available data |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Reset the buffers. As a consequence, the queue becomes empty.
|
inline |
This member function allows to retrieve a buffer ready to be read, if available.
| buffer | the available buffer will be assigned here if available |
| actualSize | the actual size of the buffer, as reported by the writer side |
|
inline |
This member function allows to retrieve a buffer ready to be written, if available.
| buffer | the available buffer will be assigned here if available |