Supplies the mutual exclusion and guard mechanisms for synchronizing member functions.
More...
template<class Mutex>
class RWTMonitor< Mutex >
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.
- Example
#include <rw/sync/RWMutexLock.h>
#include <rw/sync/RWTMonitor.h>
public:
void myFunc1(void);
void myFunc2(void) const;
private:
void helper(void) const;
};
void MyClass::myFunc1(void) {
{
myFunc2();
}
}
void MyClass::myFunc2(void) const {
helper();
}
void MyClass::helper(void) const {
}
Supplies the mutual exclusion and guard mechanisms for synchronizing member functions.
Definition RWTMonitor.h:107
RWTLockGuard< RWTMonitor< Mutex > > LockGuard
Definition RWTMonitor.h:196
RWTMonitor< Mutex > & monitor(void) const
Definition RWTMonitor.h:280
RWTUnlockGuard< RWTMonitor< Mutex > > UnlockGuard
Definition RWTMonitor.h:201
bool isAcquired(void) const
- See also
- RWMutexLock, RWTLockGuard, RWTUnlockGuard, RWTTryLockGuard