Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Threads Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

RWPCBufferBase

Module:  Threads   Package:  Interthread Communication


RWPCBufferBase RWTMonitor<RWMutexLock>

Local Index

Members

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

bool 
canRead() const;
     
bool 
canWrite() const;
void 
close();
size_t 
entries() const;
void
flush();
size_t 
getCapacity() const;
RWFunctor0
getCloseCallback() const;
RWFunctor0
getEmptyCallback() const;
RWFunctor0
getFullCallback() const;
RWFunctor0
getOpenCallback() const;
bool
isOpen() const;
void 
open();
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 DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.