Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | Related Functions
FixedBuffer Class Reference

A buffer class that holds a known capacity of fixed sized objects defined during creation. More...

#include <buffer.h>

Inheritance diagram for FixedBuffer:
Inheritance graph
[legend]
Collaboration diagram for FixedBuffer:
Collaboration graph
[legend]

Public Member Functions

 FixedBuffer (size_t capacity, size_t objsize)
 Create a buffer of known capacity for objects of a specified size. More...
 
 FixedBuffer (const FixedBuffer &fb)
 Create a copy of an existing fixed size buffer and duplicate it's contents. More...
 
virtual ~FixedBuffer ()
 Destroy the fixed buffer and free the memory used to store objects. More...
 
FixedBufferoperator= (const FixedBuffer &fb)
 
bool isValid (void)
 New virtual to test if buffer is a valid object. 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...
 
size_t wait (void *buf, timeout_t timeout=0)
 Let one or more threads wait for an object to become available in the buffer. More...
 
bool wait (timeout_t timer=0, bool locked=false)
 Wait to be signaled from another thread. More...
 
size_t post (void *buf, timeout_t timeout=0)
 Post an object into the buffer and enable a waiting thread to receive it. More...
 
size_t peek (void *buf)
 Peek at the current content (first object) in the buffer. More...
 
void signal (bool broadcast)
 Signal a conditional object and a waiting threads. More...
 
void enterMutex (void)
 Locks the conditional's mutex for this thread. More...
 
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. More...
 
bool tryEnterMutex (void)
 Tries to lock the conditional for the current thread. More...
 
bool test (void)
 
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread. More...
 
void unlock (void)
 

Static Public Attributes

static const size_t timeout
 value to return when a timed operation returned with a timeout. More...
 

Protected Member Functions

size_t onPeek (void *buf)
 Return the first object in the buffer. More...
 
size_t onWait (void *buf)
 Wait for and return a fixed object in the buffer. More...
 
size_t onPost (void *buf)
 Post an object of the appropriate size into the buffer. More...
 

Private Attributes

char * buf
 
char * head
 
char * tail
 
size_t objsize
 

Related Functions

(Note that these are not member functions.)

size_t peek (Buffer &b, void *o)
 
size_t get (Buffer &b, void *o, timeout_t t=0)
 
size_t put (Buffer &b, void *o, timeout_t t=0)
 

Detailed Description

A buffer class that holds a known capacity of fixed sized objects defined during creation.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m producer/consumer buffer for fixed size objects.

Definition at line 190 of file buffer.h.

Constructor & Destructor Documentation

FixedBuffer::FixedBuffer ( size_t  capacity,
size_t  objsize 
)

Create a buffer of known capacity for objects of a specified size.

Parameters
capacityof the buffer.
objsizefor each object held in the buffer.
FixedBuffer::FixedBuffer ( const FixedBuffer fb)

Create a copy of an existing fixed size buffer and duplicate it's contents.

Parameters
fbexisting FixedBuffer object.
virtual FixedBuffer::~FixedBuffer ( )
virtual

Destroy the fixed buffer and free the memory used to store objects.

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  )
inlineinherited

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  )
inlineinherited

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.

bool FixedBuffer::isValid ( void  )
virtual

New virtual to test if buffer is a valid object.

Returns
true if object is valid.

Reimplemented from Buffer.

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.

size_t FixedBuffer::onPeek ( void *  buf)
protectedvirtual

Return the first object in the buffer.

Returns
predefined size of this buffers objects.
Parameters
bufpointer to copy contents of head of buffer to.

Implements Buffer.

size_t FixedBuffer::onPost ( void *  buf)
protectedvirtual

Post an object of the appropriate size into the buffer.

Returns
predefined size of this buffers objects.
Parameters
bufpointer to data to copy into the buffer.

Implements Buffer.

size_t FixedBuffer::onWait ( void *  buf)
protectedvirtual

Wait for and return a fixed object in the buffer.

Returns
predefined size of this buffers objects.
Parameters
bufpointer to hold object returned from the buffer.

Implements Buffer.

FixedBuffer& FixedBuffer::operator= ( const FixedBuffer fb)
size_t Buffer::peek ( void *  buf)
inherited

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

Returns
size of object in the buffer.
Parameters
bufpointer to store object found in the buffer.
size_t Buffer::post ( void *  buf,
timeout_t  timeout = 0 
)
inherited

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

Returns
size of object posted in bytes.
Parameters
bufpointer to object to store in the buffer.
timeouttime to wait.
void Conditional::signal ( bool  broadcast)
inherited

Signal a conditional object and a waiting threads.

Parameters
broadcastthis signal to all waiting threads if true.
bool Conditional::test ( void  )
inlineinherited

Definition at line 701 of file thread.h.

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

Definition at line 711 of file thread.h.

size_t Buffer::wait ( void *  buf,
timeout_t  timeout = 0 
)
inherited

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
bufpointer to store object retrieved from the buffer.
timeouttime to wait.
bool Conditional::wait ( timeout_t  timer = 0,
bool  locked = false 
)
inherited

Wait to be signaled from another thread.

Parameters
timertime period to wait.
lockedflag if already locked the mutex.

Friends And Related Function Documentation

size_t get ( Buffer b,
void *  o,
timeout_t  t = 0 
)
related

Definition at line 350 of file buffer.h.

size_t peek ( Buffer b,
void *  o 
)
related

Definition at line 358 of file buffer.h.

size_t put ( Buffer b,
void *  o,
timeout_t  t = 0 
)
related

Definition at line 354 of file buffer.h.

Field Documentation

char* FixedBuffer::buf
private

Definition at line 193 of file buffer.h.

char * FixedBuffer::head
private

Definition at line 193 of file buffer.h.

size_t FixedBuffer::objsize
private

Definition at line 194 of file buffer.h.

char * FixedBuffer::tail
private

Definition at line 193 of file buffer.h.

const size_t Buffer::timeout
staticinherited

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: