#include <thread.h>
Inheritance diagram for Buffer::
Public Methods | |
Buffer (size_t capacity) | |
Create a buffer object of known capacity. More... | |
virtual | ~Buffer () |
In derived functions, may be used to free the actual memory used to hold buffered data. More... | |
size_t | getSize (void) |
Return the capacity of the buffer as specified at creation. More... | |
size_t | getUsed (void) |
Return the current capacity in use for the buffer. More... | |
int | Wait (void *buf) |
Let one or more threads wait for an object to become available in the buffer. More... | |
int | Post (void *buf) |
Post an object into the buffer and enable a waiting thread to receive it. More... | |
int | Peek (void *buf) |
Peek at the current content (first object) in the buffer. More... | |
virtual bool | isValid (void) |
New virtual to test if buffer is a valid object. More... | |
Protected Methods | |
virtual int | OnPeek (void *buf)=0 |
Invoke derived class buffer peeking method. More... | |
virtual int | OnWait (void *buf)=0 |
Invoke derived class object request from buffer. More... | |
virtual int | OnPost (void *buf)=0 |
Invoke derived class posting of object to buffer. More... |
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.
|
Create a buffer object of known capacity.
|
|
In derived functions, may be used to free the actual memory used to hold buffered data.
|
|
Invoke derived class buffer peeking method.
Reimplemented in FixedBuffer. |
|
Invoke derived class posting of object to buffer.
Reimplemented in FixedBuffer. |
|
Invoke derived class object request from buffer.
Reimplemented in FixedBuffer. |
|
Peek at the current content (first object) in the buffer.
|
|
Post an object into the buffer and enable a waiting thread to receive it.
|
|
Let one or more threads wait for an object to become available in the buffer. The waiting thread(s) will wait forever if no object is ever placed into the buffer.
|
|
Return the capacity of the buffer as specified at creation.
|
|
Return the current capacity in use for the buffer. Free space is technically getSize() - getUsed().
|
|
New virtual to test if buffer is a valid object.
Reimplemented in FixedBuffer. |