Module: Threads Package: Synchronization
RWNullMutexLock RWSynchObject
#include <rw/sync/RWNullMutexLock.h>
An RWNullMutexLock is an efficient stand-in for a mutual exclusion lock, particularly when you know that critical sections of code do not need synchronization. For example, you may know that it is not possible for more than one thread to simultaneously enter a section of code that would otherwise require locking. In such cases you can use an RWNullMutexLock to eliminate the unnecessary overhead of acquiring and releasing a mutex. This class can also be used to instantiate a single-threaded or non-thread-safe version of a template classes that accept a mutex parameter, such as RWTMonitor<Mutex>.
#include <rw/sync/RWMutexLock.h> #include <rw/sync/RWNullMutexLock.h> #if SYNCHRONIZATION_REQUIRED typedef RWMutexLock MUTEX; #else typedef RWNullMutexLock MUTEX; #endif MUTEX mutex; mutex.acquire(); // No cost if synchronization not required // critical section mutex.release(); // Same thing, this time using a guard: { MUTEX::Lockguard lock(mutex); // does nothing if // synchronization not required // critical section // If synchronization required, lock will be released // automatically }
typedef RWTLockGuard<RWNullMutexLock> LockGuard; typedef RWTReadLockGuard<RWNullMutexLock> ReadLockGuard; typedef RWTWriteLockGuard<RWNullMutexLock> WriteLockGuard; typedef RWTTryLockGuard<RWNullMutexLock> TryLockGuard; typedef RWTTryReadLockGuard<RWNullMutexLock> TryReadLockGuard; typedef RWTTryWriteLockGuard<RWNullMutexLock>
TryWriteLockGuard; typedef RWTUnlockGuard<RWNullMutexLock> UnlockGuard; typedef RWTReadUnlockGuard<RWNullMutexLock> ReadUnlockGuard; typedef RWTWriteUnlockGuard<RWNullMutexLock> WriteUnlockGuard;
Predefined types for compatible guards.
RWNullMutexLock(RWStaticCtor);
Creates an RWNullMutexLock.
RWMutexLock(RWCancellationState
state=RW_CANCELLATION_DISABLED);
Creates an RWNullMutexLock. state is ignored.
~RWMutexLock();
Destructor.
void acquire();
Does nothing
RWWaitStatus acquire(unsigned long milliseconds);
Returns RW_THR_ACQUIRED.
void acquireRead();
Does nothing.
RWWaitStatus acquireRead(unsigned long milliseconds);
Returns RW_THR_ACQUIRED.
void acquireWrite();
Does nothing.
RWWaitStatus acquireWrite(unsigned long milliseconds);
Returns RW_THR_ACQUIRED.
bool isAcquired() const;
Returns true.
NOTE -- Only available from the debug version of the Threads Module.
void release();
Does nothing.
bool tryAcquire();
Returns true.
bool tryAcquireRead();
Returns true.
bool tryAcquireWrite();
Returns true.
RWNullMutexLock(const RWNullMutexLock& second);
Copy construction prohibited.
RWNullMutexLock& operator=(const RWNullMutexLock& second);
Assignment prohibited.
RWMutexLock, RWTLockGuard<Resource>, RWTUnlockGuard<Resource>, RWTTryLockGuard<Resource>
© 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.