The buffer class represents an IPC service that is built upon a buffer of fixed capacity that can be used to transfer objects between one or more producer and consumer threads.
More...
|
| Buffer (size_t capacity) |
| Create a buffer object of known capacity.
|
|
virtual | ~Buffer () |
| In derived functions, may be used to free the actual memory used to hold buffered data.
|
|
size_t | getSize (void) |
| Return the capacity of the buffer as specified at creation.
|
|
size_t | getUsed (void) |
| Return the current capacity in use for the buffer.
|
|
size_t | wait (void *buf, timeout_t timeout=0) |
| Let one or more threads wait for an object to become available in the buffer.
|
|
size_t | post (void *buf, timeout_t timeout=0) |
| Post an object into the buffer and enable a waiting thread to receive it.
|
|
size_t | peek (void *buf) |
| Peek at the current content (first object) in the buffer.
|
|
virtual bool | isValid (void) |
| New virtual to test if buffer is a valid object.
|
|
| Conditional (const char *id=NULL) |
| Create an instance of a conditional.
|
|
virtual | ~Conditional () |
| Destroy the conditional.
|
|
void | signal (bool broadcast) |
| Signal a conditional object and a waiting threads.
|
|
bool | wait (timeout_t timer=0, bool locked=false) |
| Wait to be signaled from another thread.
|
|
void | enterMutex (void) |
| Locks the conditional's mutex for this thread.
|
|
void | lock (void) |
| In the future we will use lock in place of enterMutex since the conditional composite is not a recursive mutex, and hence using enterMutex may cause confusion in expectation with the behavior of the Mutex class.
|
|
bool | tryEnterMutex (void) |
| Tries to lock the conditional for the current thread.
|
|
bool | test (void) |
|
void | leaveMutex (void) |
| Leaving a mutex frees that mutex for use by another thread.
|
|
void | unlock (void) |
|
The buffer class represents an IPC service that is built upon a buffer of fixed capacity that can be used to transfer objects between one or more producer and consumer threads.
Producer threads post objects into the buffer, and consumer threads wait for and receive objects from the buffer. Semaphores are used to to block the buffer from overflowing and indicate when there is data available, and mutexes are used to protect multiple consumers and producer threads from stepping over each other.
The buffer class is an abstract class in that the actual data being buffered is not directly specified within the buffer class itself. The buffer class should be used as a base class for a class that actually impliments buffering and which may be aware of the data types actually are being buffered. A template class could be created based on buffer for this purpose. Another possibility is to create a class derived from both Thread and Buffer which can be used to implement message passing threads.
- Author
- David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m
Producer/Consumer buffer for use between threads.