SourcePro® 2023.1 |
SourcePro® API Reference Guide |
Supplies the mutual exclusion and guard mechanisms for synchronizing member functions. More...
#include <rw/sync/RWTMonitor.h>
Protected Types | |
typedef RWTLockGuard< RWTMonitor< Mutex > > | LockGuard |
typedef RWTTryLockGuard< RWTMonitor< Mutex > > | TryLockGuard |
typedef RWTUnlockGuard< RWTMonitor< Mutex > > | UnlockGuard |
Protected Member Functions | |
RWTMonitor () | |
RWTMonitor (RWStaticCtor) | |
RWTMonitor (const RWTMonitor< Mutex > &second) | |
~RWTMonitor () | |
void | acquire () |
bool | isAcquired () const |
RWTMonitor< Mutex > & | monitor () const |
Mutex & | mutex () |
RWTMonitor< Mutex > & | operator= (const RWTMonitor< Mutex > &) |
void | release () |
bool | tryAcquire () |
Subclassing from RWTMonitor provides a convenient way to synchronize the member functions used to access the data or resources encapsulated by a class. RWTMonitor supplies the mutual exclusion and guard mechanisms for synchronizing member functions. Functions that need to be synchronized use the supplied guard type to lock the monitor upon entry and unlock it upon exit from the function.
This class provides an alternative to directly inheriting from or including a synchronization class to achieve the same purpose. If you use your own mutex for synchronization, you must cast away the const
-ness of this
in const
member functions before acquiring or releasing the mutex.
By using this class, you have access to the monitor() function, eliminates the above inconvenience by always returning a non-const
instance of the monitor. The reference returned by monitor() can be used to initialize any of the public guard types defined by the RWTMonitor class.
|
protected |
Predefined guard for use with the monitor.
|
protected |
Predefined try lock guard for use with the monitor.
|
protected |
Predefined unlock guard for use with the monitor.
|
inlineprotected |
Constructs a default monitor instance, initializing the mutex.
|
inlineprotected |
Constructs a static monitor instance. This constructor does not initialize the mutex; rather, the mutex is initialized the first time it is accessed.
|
inlineprotected |
This copy constructor does not actually copy anything (mutexes generally cannot be copied). It is provided so you can define a copy constructor in your derived class.
|
inlineprotected |
Destructor.
|
inlineprotected |
Locks the monitor by acquiring the monitor's mutex.
|
protected |
Determines whether the calling thread currently owns the monitor.
This function is primarily intended for use in precondition assertions, and is available only when you build the debug version of the module.
|
inlineprotected |
Casts away const
and returns a reference to self. This allows you to avoid explicitly casting away const
on the this
pointer in every const
member function that needs to lock the monitor.
|
inlineprotected |
Returns the monitor's mutex.
|
inlineprotected |
This assignment operator does not actually assign anything (mutexes generally cannot be assigned). It is provided so you can define an assignment operator in your derived class.
|
inlineprotected |
Unlocks the monitor by releasing the monitor's mutex.
|
inlineprotected |
Conditionally locks the monitor if the monitor can be locked without blocking.
Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |