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...
#include <buffer.h>
Inheritance diagram for Buffer:
Collaboration diagram for Buffer:
Public Member Functions
Create a buffer object of known capacity.
More...
In derived functions, may be used to free the actual memory used to hold buffered data.
More...
Return the capacity of the buffer as specified at creation.
More...
Return the current capacity in use for the buffer.
More...
Let one or more threads wait for an object to become available in the buffer.
More...
Post an object into the buffer and enable a waiting thread to receive it.
More...
Peek at the current content (first object) in the buffer.
More...
New virtual to test if buffer is a valid object.
More...
Signal a conditional object and a waiting threads.
More...
Wait to be signaled from another thread.
More...
Locks the conditional's mutex for this thread.
More...
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.
More...
Tries to lock the conditional for the current thread.
More...
Leaving a mutex frees that mutex for use by another thread.
More...
Static Public Attributes
value to return when a timed operation returned with a timeout.
More...
Protected Member Functions
virtual size_t
onPeek (void *buf)=0
Invoke derived class buffer peeking method.
More...
virtual size_t
onWait (void *buf)=0
Invoke derived class object request from buffer.
More...
virtual size_t
onPost (void *buf)=0
Invoke derived class posting of object to buffer.
More...
Private Attributes
Related Functions
(Note that these are not member functions.)
Detailed Description
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.
Definition at line 81 of file buffer.h.
Constructor & Destructor Documentation
Buffer::Buffer
(
size_t
capacity )
Create a buffer object of known capacity.
- Parameters
-
capacity is the integer capacity of the buffer.
virtual Buffer::~Buffer
(
)
virtual
In derived functions, may be used to free the actual memory used to hold buffered data.
Member Function Documentation
void Conditional::enterMutex
(
void
)
inherited
Locks the conditional's mutex for this thread.
Remember that Conditional's mutex is NOT a recursive mutex!
- See Also
- leaveMutex
size_t Buffer::getSize
(
void
)
inline
Return the capacity of the buffer as specified at creation.
- Returns
- size of buffer.
Definition at line 135 of file buffer.h.
size_t Buffer::getUsed
(
void
)
inline
Return the current capacity in use for the buffer.
Free space is technically getSize() - getUsed().
- Returns
- integer used capacity of the buffer.
- See Also
- getSize
Definition at line 144 of file buffer.h.
virtual bool Buffer::isValid
(
void
)
virtual
New virtual to test if buffer is a valid object.
- Returns
- true if object is valid.
Reimplemented in FixedBuffer.
void Conditional::leaveMutex
(
void
)
inherited
Leaving a mutex frees that mutex for use by another thread.
- See Also
- enterMutex
void Conditional::lock
(
void
)
inlineinherited
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.
- See Also
- enterMutex
Definition at line 686 of file thread.h.
virtual size_t Buffer::onPeek
(
void *
buf )
protectedpure virtual
Invoke derived class buffer peeking method.
- Returns
- size of object found.
- Parameters
-
buf pointer to copy contents of head of buffer to.
Implemented in ost::BayonneMsgport, and FixedBuffer.
virtual size_t Buffer::onPost
(
void *
buf )
protectedpure virtual
Invoke derived class posting of object to buffer.
- Returns
- size of object posted.
- Parameters
-
buf pointer to object being posted to the buffer.
Implemented in ost::BayonneMsgport, and FixedBuffer.
virtual size_t Buffer::onWait
(
void *
buf )
protectedpure virtual
Invoke derived class object request from buffer.
- Returns
- size of object returned.
- Parameters
-
buf pointer to hold object returned from the buffer.
Implemented in ost::BayonneMsgport, and FixedBuffer.
size_t Buffer::peek
(
void *
buf )
Peek at the current content (first object) in the buffer.
- Returns
- size of object in the buffer.
- Parameters
-
buf pointer to store object found in the buffer.
size_t Buffer::post
(
void *
buf,
)
Post an object into the buffer and enable a waiting thread to receive it.
- Returns
- size of object posted in bytes.
- Parameters
-
buf pointer to object to store in the buffer.
timeout time to wait.
void Conditional::signal
(
bool
broadcast )
inherited
Signal a conditional object and a waiting threads.
- Parameters
-
broadcast this signal to all waiting threads if true.
bool Conditional::test
(
void
)
inlineinherited
bool Conditional::tryEnterMutex
(
void
)
inherited
Tries to lock the conditional for the current thread.
Behaves like enterMutex , except that it doesn't block the calling thread.
- Returns
- true if locking the mutex was succesful otherwise false
- See Also
- enterMutex
-
leaveMutex
void Conditional::unlock
(
void
)
inlineinherited
size_t Buffer::wait
(
void *
buf,
)
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.
- Returns
- size of object passed by buffer in bytes.
- Parameters
-
buf pointer to store object retrieved from the buffer.
timeout time to wait.
bool Conditional::wait
(
timeout_t
timer =
0
,
bool
locked = false
)
inherited
Wait to be signaled from another thread.
- Parameters
-
timer time period to wait.
locked flag if already locked the mutex.
Friends And Related Function Documentation
Field Documentation
size_t Buffer::_size
private
size_t Buffer::_used
private
const size_t Buffer::timeout
static
value to return when a timed operation returned with a timeout.
Definition at line 118 of file buffer.h.
The documentation for this class was generated from the following file: