Module: Threads Package: Synchronization
RWFIFOMutexLock RWSynchObject
#include <rw/sync/RWFIFOMutexLock.h>
An RWFIFOMutexLock can be used to guarantee that blocking threads will acquire the mutex in the same order that they called the acquire() member function. On certain systems, thread attributes such as thread priority may be a factor in determining the order in which threads blocking on the same mutex will acquire that mutex when it is finally released. Class RWFIFOMutexLock eliminates those other factors and considers only the order of requests for acquisition.
#include <rw/sync/RWFIFOMutexLock.h> RWFIFOMutexLock fifomutex; fifomutex.acquire(); // critical section fifomutex.release(); // Same thing, this time using a guard: RWFIFOMutexLock fifomutex; { RWFIFOMutexLock::LockGuard lock(fifomutex); // critical section // Mutex will be released in RWFIFOMutexLock::LockGuard // destructor before leaving scope, especially important // if an exception is thrown! }
typedef RWTLockGuard<RWFIFOMutexLock> LockGuard; typedef RWTLockGuard<RWFIFOMutexLock> ReadLockGuard; typedef RWTLockGuard<RWFIFOMutexLock> WriteLockGuard; typedef RWTTryLockGuard<RWFIFOMutexLock> TryLockGuard; typedef RWTTryLockGuard<RWFIFOMutexLock> TryReadLockGuard; typedef RWTTryLockGuard<RWFIFOMutexLock> TryWriteLockGuard; typedef RWTUnlockGuard<RWFIFOMutexLock> UnlockGuard; typedef RWTUnlockGuard<RWFIFOMutexLock> ReadUnlockGuard; typedef RWTUnlockGuard<RWFIFOMutexLock> WriteUnlockGuard;
Predefined types for compatible guards.
RWFIFOMutexLock(RWCancellationState state=RW_CANCELLATION_DISABLED);
Creates and initializes an RWFIFOMutexLock. The thread cancellation state of the object is initialized to state.
RWFIFOMutexLock(RWStaticCtor);
Constructs a static instance, but does not initialize the RWFIFOMutexLock. The RWFIFOMutexLock will be initialized on first use.
~RWFIFOMutexLock();
Recovers any system resources used to implement the RWFIFOMutexLock.
void acquire();
Causes the current thread to block until the mutex is released, at which time the thread acquires the mutex and continues. If other threads are blocked waiting for this same mutex, the first thread that called this member function will acquire the mutex and continue. Possible exceptions include RWCancellation and RWTHRInternalError.
In single-threaded builds, this method will not block. On success, it will return immediately. Otherwise it will fail with a debug assertion or a thrown RWTHRInternalError.
RWWaitStatus acquire(unsigned long milliseconds);
Blocks at least for the specified number of milliseconds, or until the mutex is released -- whichever comes first. If the mutex is released within the specified time, acquires it, and continues. If the mutex is not released, returns RW_THR_TIMEOUT. Possible exceptions include RWCancellation and RWTHRInternalError.
In single-threaded builds, this method will immediately return RW_THR_ACQUIRED if the resource is currently available, otherwise it will return RW_THR_TIMEOUT.
void acquireRead();
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
RWWaitStatus acquireRead(unsigned long milliseconds);
Calls acquire(milliseconds). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
void acquireWrite();
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
RWWaitStatus acquireWrite(unsigned long milliseconds);
Calls acquire(milliseconds). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
bool isAcquired() const;
Determines whether the calling thread currently owns the mutex.
NOTE -- Only available from the debug version of the module.
void release();
Releases the mutex, making it available. Possible exceptions include RWTHRInternalError.
bool tryAcquire();
Tries to acquire mutex without blocking. Returns true if successful. Possible exceptions include RWCancellation and RWTHRInternalError.
bool tryAcquireRead();
Calls tryAcquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
bool tryAcquireWrite();
Calls tryAcquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
RWFIFOMutexLock(const RWFIFOMutexLock& second);
Copy construction prohibited.
RWFIFOMutexLock& operator=(const RWFIFOMutexLock& second);
Assignment prohibited.
RWMutexLock, RWTRecursiveLock<Mutex>
© 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.