Base class that provides buffered producer-consumer synchronization semantics for exchanging guarded and prioritized values between cooperating threads. More...
#include <rw/itc/RWTPCValBufferBaseGuardedPrioritized.h>
Public Member Functions | |
virtual | ~RWTPCValBufferBaseGuardedPrioritized (void) |
bool | tryWrite (const Type &value) |
bool | tryWrite (const Type &value, const RWTFunctor< bool()> &guard) |
bool | tryWrite (long priority, const Type &value) |
bool | tryWrite (long priority, const Type &value, const RWTFunctor< bool()> &guard) |
void | write (const Type &value) |
RWWaitStatus | write (const Type &value, unsigned long milliseconds) |
void | write (const Type &value, const RWTFunctor< bool()> &guard) |
RWWaitStatus | write (const Type &value, const RWTFunctor< bool()> &guard, unsigned long milliseconds) |
void | write (long priority, const Type &value) |
RWWaitStatus | write (long priority, const Type &value, unsigned long milliseconds) |
void | write (long priority, const Type &value, const RWTFunctor< bool()> &guard) |
RWWaitStatus | write (long priority, const Type &value, const RWTFunctor< bool()> &guard, unsigned long milliseconds) |
Public Member Functions inherited from RWTPCValBufferBaseGuarded< Type, GuardAndPriorityDecorator > | |
virtual | ~RWTPCValBufferBaseGuarded (void) |
Type | peek (void) |
RWWaitStatus | peek (Type &result, unsigned long milliseconds) |
Type | read (void) |
RWWaitStatus | read (Type &result, unsigned long milliseconds) |
bool | tryPeek (Type &value) |
bool | tryRead (Type &value) |
bool | tryWrite (const Type &value, const RWTFunctor< bool()> &guard) |
void | write (const Type &value, const RWTFunctor< bool()> &guard) |
RWWaitStatus | write (const Type &value, const RWTFunctor< bool()> &guard, unsigned long milliseconds) |
Public Member Functions inherited from RWTPCValBufferBaseDecorated< Type, GuardAndPriorityDecorator > | |
virtual | ~RWTPCValBufferBaseDecorated (void) |
Type | peek (void) |
RWWaitStatus | peek (Type &result, unsigned long milliseconds) |
Type | read (void) |
RWWaitStatus | read (Type &result, unsigned long milliseconds) |
bool | tryPeek (Type &result) |
bool | tryRead (Type &result) |
bool | tryWrite (const Type &value) |
void | write (const Type &value) |
RWWaitStatus | write (const Type &value, unsigned long milliseconds) |
Public Member Functions inherited from RWTPCValBufferBasePrioritized< Type, GuardAndPriorityDecorator > | |
virtual | ~RWTPCValBufferBasePrioritized (void) |
bool | tryWrite (long priority, const Type &value) |
void | write (long priority, const Type &value) |
RWWaitStatus | write (long priority, const Type &value, unsigned long milliseconds) |
Additional Inherited Members | |
Protected Types inherited from RWTMonitor< RWMutexLock > | |
typedef RWTLockGuard< RWTMonitor< RWMutexLock > > | LockGuard |
typedef RWTTryLockGuard< RWTMonitor< RWMutexLock > > | TryLockGuard |
typedef RWTUnlockGuard< RWTMonitor< RWMutexLock > > | UnlockGuard |
Protected Member Functions inherited from RWTPCValBufferBase< GuardAndPriorityDecorator > | |
virtual | ~RWTPCValBufferBase (void) |
GuardAndPriorityDecorator | peek (void) |
RWWaitStatus | peek (GuardAndPriorityDecorator &result, unsigned long milliseconds) |
GuardAndPriorityDecorator | read (void) |
RWWaitStatus | read (GuardAndPriorityDecorator &result, unsigned long milliseconds) |
bool | tryPeek (GuardAndPriorityDecorator &result) |
bool | tryRead (GuardAndPriorityDecorator &result) |
bool | tryWrite (const GuardAndPriorityDecorator &value) |
void | write (const GuardAndPriorityDecorator &value) |
RWWaitStatus | write (const GuardAndPriorityDecorator &value, unsigned long milliseconds) |
virtual | ~RWPCBufferBase (void) |
bool | canRead (void) const |
bool | canWrite (void) const |
void | close (void) |
size_t | entries (void) const |
void | flush (void) |
size_t | getCapacity (void) const |
RWTFunctor< void()> | getCloseCallback (void) const |
RWTFunctor< void()> | getEmptyCallback (void) const |
RWTFunctor< void()> | getFullCallback (void) const |
RWTFunctor< void()> | getOpenCallback (void) const |
bool | isOpen (void) const |
void | open (void) |
size_t | setCapacity (size_t maxCapacity) |
void | setCloseCallback (const RWTFunctor< void()> &onCloseCallback) |
void | setEmptyCallback (const RWTFunctor< void()> &onEmptyCallback) |
void | setFullCallback (const RWTFunctor< void()> &onFullCallback) |
void | setOpenCallback (const RWTFunctor< void()> &onOpenCallback) |
Protected Member Functions inherited from RWTMonitor< RWMutexLock > | |
RWTMonitor () | |
RWTMonitor (RWStaticCtor) | |
RWTMonitor (const RWTMonitor< RWMutexLock > &second) | |
~RWTMonitor () | |
void | acquire () |
bool | isAcquired () const |
RWTMonitor< RWMutexLock > & | monitor () const |
RWMutexLock & | mutex () |
RWTMonitor< RWMutexLock > & | operator= (const RWTMonitor< RWMutexLock > &) |
void | release () |
bool | tryAcquire () |
RWTPCValBufferBaseGuardedPrioritized is the base class for the family of classes that provides buffered producer-consumer synchronization semantics for exchanging guarded and prioritized values 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 write operations provided by this class and its subclasses bind additional data items to each value prior to storing that value in an internal buffer. These additional data items, or decorations, include a guard functor instance and a priority value. The guard functor is used during read operations to determine whether the associated value is currently eligible for retrieval from the buffer. The priority value is used during write operations to determine a value's insertion point within the buffer, such that the set of unread values will be retrieved in priority order when eventually read from the buffer. The template parameter GuardAndPriorityDecorator
identifies the class that is used to encapsulate the data value, guard functor, and priority value as a single object for storage in the internal buffer. The decorator class used by subclasses to instantiate this class is intended for the Threads Module's internal use, and is not documented as part of the public interface.
|
virtual |
Virtual destructor.
|
inline |
This function provides the same capabilities and behavior as tryWrite(long,const Type&,const RWTFunctor<bool()>&) except that this function attaches an empty guard functor instance and a priority value of zero to each value.
|
inline |
This function provides the same capabilities and behavior as tryWrite(long,const Type&,const RWTFunctor<bool()>&) except that this function attaches a priority value of zero to each value.
|
inline |
This function provides the same capabilities and behavior as tryWrite(long,const Type&,const RWTFunctor<bool()>&) except that this function attaches an empty guard functor instance a priority value of zero to each value.
bool RWTPCValBufferBaseGuardedPrioritized< Type, GuardAndPriorityDecorator >::tryWrite | ( | long | priority, |
const Type & | value, | ||
const RWTFunctor< bool()> & | guard | ||
) |
Inserts a value with the specified priority into the buffer at a position determined by the implementation supplied in derived classes, but only if the value may be written immediately; in other words, only if there is sufficient free capacity.
If the buffer is open and has sufficient capacity to hold another value, this function inserts the value, and returns a value of true
to indicate that the write succeeded. If the buffer is open and full, this function immediately returns a value of false
to indicate that the write was unsuccessful. If the buffer is closed, this function immediately returns by throwing an RWTHRClosedException.
Calling this function on an full buffer may result in the invocation of the on-full callback functor, if a valid one has been registered. The on-full callback functor is guaranteed to execute only within a writer thread. Calling this function on a full buffer results in the invocation of an on-full callback functor under either of these scenarios:
Repeated attempts to write to a full buffer does not result in repeated invocations of the callback functor. Once the full buffer is read from, however, it resets the callback trigger. If the buffer again becomes full, the first thread to attempt to write to it causes another invocation of the on-full callback.
While this function guarantees not to block the caller if the buffer is full, it cannot prevent the on-full callback functor, if executed, from indirectly blocking the caller.
This function takes three parameters:
long
that is used to determine the insertion point of the value within the buffer. A value with a greater priority value is positioned to be read before a value of lower priority. Values of equal priority are positioned as determined by the implementation supplied in derived classes.const
reference to an instance of the type used to instantiate this template class.
|
inline |
This function provides the same capabilities and behavior as write(long,const Type&,const RWTFunctor<bool()>&) except that this function attaches an empty guard functor instance and a priority value of zero to each value.
|
inline |
This function provides the same capabilities and behavior as write(long,const Type&,const RWTFunctor<bool()>&,unsigned long) except that this function attaches an empty guard functor instance and a priority value of zero to each value.
|
inline |
This function provides the same capabilities and behavior as write(long,const Type&,const RWTFunctor<bool()>&) except that this function attaches a priority value of zero to each value.
|
inline |
This function provides the same capabilities and behavior as write(long,const Type&,const RWTFunctor<bool()>&,unsigned long) except that this function attaches a priority value of zero to each value.
|
inline |
This function provides the same capabilities and behavior as write(long,const Type&,const RWTFunctor<bool()>&) except that this function attaches an empty guard functor instance to each value.
|
inline |
This function provides the same capabilities and behavior as write(long,const Type&,const RWTFunctor<bool()>&,unsigned long) except that this function attaches an empty guard functor instance to each value.
void RWTPCValBufferBaseGuardedPrioritized< Type, GuardAndPriorityDecorator >::write | ( | long | priority, |
const Type & | value, | ||
const RWTFunctor< bool()> & | guard | ||
) |
Inserts a value with the specified priority into the buffer at a position determined by the implementation supplied in derived classes.
If the buffer is open and has sufficient capacity to hold another value, this function inserts the value. If the buffer is open and full, this function blocks the calling thread until the buffer is no longer full (because another thread or threads have read values or have changed the maximum capacity), or until the buffer is closed.
If the buffer is closed while the calling thread is blocked and waiting within this function for room to write, the calling thread is unblocked and the function returns by throwing an RWTHRClosedException.
If the buffer is already closed when this function is called, the function immediately returns by throwing an RWTHRClosedException.
Calling this function on an full buffer may result in the invocation of the on-full callback functor, if a valid one has been registered. The on-full callback functor is guaranteed to execute only within a writer thread. Calling this function on a full buffer results in the invocation of an on-full callback functor under either of these scenarios:
Repeated attempts to write to a full buffer does not result in repeated invocations of the callback functor. Once the full buffer is read from, however, it resets the callback trigger. If the buffer again becomes full, the first thread to attempt to write to it causes another invocation of the on-full callback.
This function takes three parameters.
long
that is used to determine the insertion point of the value within the buffer. A value with a greater priority value is positioned to be read before a value of lower priority. Values of equal priority are positioned as determined by the implementation supplied in derived classes.const
reference to an instance of the type used to instantiate this template class.RWWaitStatus RWTPCValBufferBaseGuardedPrioritized< Type, GuardAndPriorityDecorator >::write | ( | long | priority, |
const Type & | value, | ||
const RWTFunctor< bool()> & | guard, | ||
unsigned long | milliseconds | ||
) |
Inserts a value with the specified priority into the buffer at a position determined by the implementation supplied in derived classes.
If the buffer is open and has sufficient capacity to hold another value, this function inserts the value and returns RW_THR_COMPLETED to indicate that the write succeeded. If the buffer is open and full, this function blocks the calling thread until the buffer is no longer full (because another thread or threads have read values or have changed the maximum capacity), or until the buffer is closed, or until the specified amount of time passes. If sufficient space does not become available within the specified amount of time, the function returns a value of RW_THR_TIMEOUT.
If the buffer is closed while the calling thread is blocked and waiting within this function for room to write, the calling thread is unblocked and the function returns by throwing an RWTHRClosedException. If the buffer is already closed when this function is called, the function immediately returns by throwing an RWTHRClosedException.
Calling this function on an full buffer may result in the invocation of the on-full callback functor, if a valid one has been registered. The on-full callback functor is guaranteed to execute only within a writer thread. Calling this function on a full buffer results in the invocation of an on-full callback functor under either of these scenarios:
Repeated attempts to write to a full buffer does not result in repeated invocations of the callback functor. Once the full buffer is read from, however, it resets the callback trigger. If the buffer again becomes full, the first thread to attempt to write to it causes another invocation of the on-full callback.
While this function guarantees to wait, if necessary, for a period of time equal to or greater than the specified number of milliseconds, it cannot guarantee that the thread is actually scheduled for execution at the end of the timeout period. It cannot prevent the on-full callback functor from indirectly blocking the caller for an indefinite period of time.
This function takes four parameters:
long
that is used to determine the insertion point of the value within the buffer. A value with a greater priority value is positioned to be read before a value of lower priority. Values of equal priority are positioned as determined by the implementation supplied in derived classes.const
reference to an instance of the type used to instantiate this template class.unsigned long
value that specifies the maximum number of milliseconds to wait for the operation to complete.
Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |