Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWPCBufferBase


RWPCBufferBase RWTMonitor<RWMutexLock>

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Member Functions

Package

Interthread Communication

Header File

#include <rw/itc/RWPCBufferBase.h> 

Description

RWPCBufferBase is the base class for the family of classes that provide buffered producer-consumer synchronization semantics for exchanging data between cooperating threads.

In the producer-consumer synchronization model, reader threads (consumers) are blocked while a buffer is empty, and writer threads (producers) are blocked while a buffer is full. A buffer is considered full when the number of unread entries equals or exceeds some user-specified maximum capacity.

The maximum capacity of a buffer may be limited by using a constructor argument or the setCapacity() function. A maximum capacity value of zero results in a buffer that imposes no limit on the number of unread entries that may be inserted.

This class provides functions for opening and closing a buffer instance. By default, buffer instances are constructed in the open state. Any number of threads may read from, or write to, the buffer while the buffer is in the open state. Once closed, any entries that remain in the buffer may be safely read from the buffer, but any attempts to read from the buffer once it is empty, or any attempts to write to the buffer while it is closed, result in an exception being thrown.

A closed buffer may be reopened at any time. Any attempt to close a buffer that is already closed, or to open a buffer that is already open, is ignored.

Single functors may be registered and invoked as callback objects for the following buffer events:

On-Empty A thread calls a read or peek function and finds that it is the first reader to discover that the buffer is empty.
On-Full A thread calls a write function and finds that it is the first writer to discover that the buffer is full.
On-Close A thread closes an open buffer.
On-Open A thread opens a closed buffer.

The public functions of this class are internally synchronized, and instances of this class are safe for use in the presence of multiple threads.

Public Destructor

virtual
~RWPCBufferBase();

Public Member Functions

RWBoolean 
canRead(void) const;
     
RWBoolean 
canWrite(void) const;
void 
close(void);
size_t 
entries(void) const;
void
flush(void);
size_t 
getCapacity() const;
RWFunctor0
getCloseCallback(void) const;
RWFunctor0
getEmptyCallback(void) const;
RWFunctor0
getFullCallback(void) const;
RWFunctor0
getOpenCallback(void) const;
RWBoolean
isOpen(void) const;
void 
open(void);
size_t 
setCapacity(size_t maxCapacity);
void
setCloseCallback(const RWFunctor0& onCloseCallback);
void
setEmptyCallback(const RWFunctor0& onEmptyCallback);
void
setFullCallback(const RWFunctor0& onFullCallback);
void
setOpenCallback(const RWFunctor0& onOpenCallback);

See Also

RWTPCPtrQueue<Type>, RWTPCPtrStack<Type>, RWTPCValQueue<Type>, RWTPCValStack<Type>



Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.