Buffer Class Reference

[APE Index] [APE Hierarchy] [Headers]


Producer/Consumer buffer for use between threads. More...

#include <thread.h>

Public Members

Protected Members


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.


Buffer(size_t capacity) [public]

Create a buffer object of known capacity.

Parameters:
capcity is the integer capacity of the buffer.

~Buffer() [public virtual]

In derived functions, may be used to free the actual memory used to hold buffered data.

inline size_t getSize(void) [public]

Return the capacity of the buffer as specified at creation.

Returns:
size of buffer.

inline size_t getUsed(void) [public]

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

int Wait(void *buf) [public]

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.

Parameters:
buf pointer to store object retrieved from the buffer.
Returns:
size of object passed by buffer in bytes.

int Post(void *buf) [public]

Post an object into the buffer and enable a waiting thread to receive it.

Parameters:
buf pointer to object to store in the buffer.
Returns:
size of object posted in bytes.

int Peek(void *buf) [public]

Peek at the current content (first object) in the buffer.

Parameters:
buf pointer to store object found in the buffer.
Returns:
size of object in the buffer.

int OnPeek(void *buf) [protected virtual]

Invoke derived class buffer peeking method.

Parameters:
buf pointer to copy contents of head of buffer to.
Returns:
size of object found.

int OnWait(void *buf) [protected virtual]

Invoke derived class object request from buffer.

Parameters:
buf pointer to hold object returned from the buffer.
Returns:
size of object returned.

int OnPost(void *buf) [protected virtual]

Invoke derived class posting of object to buffer.

Parameters:
buf pointer to object being posted to the buffer.
Returns:
size of object posted.

  • Author: David Sugar <dyfet@ostel.com>
  • Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
Kdoc