SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWFIFOMutexLock Class Reference

Guarantees that blocking threads acquire the mutex in the same order that they called the acquire() member function. More...

#include <rw/sync/RWFIFOMutexLock.h>

Inheritance diagram for RWFIFOMutexLock:
RWSynchObject

Public Types

typedef RWTLockGuard< RWFIFOMutexLockLockGuard
 
typedef RWTLockGuard< RWFIFOMutexLockReadLockGuard
 
typedef RWTUnlockGuard< RWFIFOMutexLockReadUnlockGuard
 
typedef RWTTryLockGuard< RWFIFOMutexLockTryLockGuard
 
typedef RWTTryLockGuard< RWFIFOMutexLockTryReadLockGuard
 
typedef RWTTryLockGuard< RWFIFOMutexLockTryWriteLockGuard
 
typedef RWTUnlockGuard< RWFIFOMutexLockUnlockGuard
 
typedef RWTLockGuard< RWFIFOMutexLockWriteLockGuard
 
typedef RWTUnlockGuard< RWFIFOMutexLockWriteUnlockGuard
 

Public Member Functions

 RWFIFOMutexLock (RWCancellationState state=0)
 
 RWFIFOMutexLock (RWStaticCtor)
 
 ~RWFIFOMutexLock ()
 
void acquire ()
 
RWWaitStatus acquire (unsigned long milliseconds)
 
void acquireRead ()
 
RWWaitStatus acquireRead (unsigned long milliseconds)
 
void acquireWrite ()
 
RWWaitStatus acquireWrite (unsigned long milliseconds)
 
bool isAcquired () const
 
void release ()
 
bool tryAcquire ()
 
bool tryAcquireRead ()
 
bool tryAcquireWrite ()
 
- Public Member Functions inherited from RWSynchObject
void disableCancellation ()
 
void enableCancellation (RWCancellationState)
 
bool isCancellationEnabled () const
 
void setCancellation (RWCancellationState)
 

Private Member Functions

 RWFIFOMutexLock (const RWFIFOMutexLock &second)
 
RWFIFOMutexLockoperator= (const RWFIFOMutexLock &second)
 

Additional Inherited Members

- Protected Member Functions inherited from RWSynchObject
 RWSynchObject (const RWSynchObject &second)
 
 RWSynchObject (RWCancellationState state=0)
 
 RWSynchObject (RWStaticCtor)
 
RWSynchObjectoperator= (const RWSynchObject &second)
 
void testCancellation ()
 

Detailed Description

An RWFIFOMutexLock can be used to guarantee that blocking threads 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 acquire that mutex when it is finally released. Class RWFIFOMutexLock eliminates any other factors and considers only the order of requests for acquisition.

Example
#include <rw/sync/RWFIFOMutexLock.h>
int main() {
RWFIFOMutexLock fifomutex;
fifomutex.acquire();
// critical section
fifomutex.release();
// Same thing, this time using a guard:
{
RWFIFOMutexLock::LockGuard lock(fifomutex);
// critical section
// Mutex will be released in RWFIFOMutexLock::LockGuard
// destructor before leaving scope, especially important
// if an exception is thrown!
}
return 0;
}
Guarantees that blocking threads acquire the mutex in the same order that they called the acquire() m...
Definition RWFIFOMutexLock.h:66
A guard that acquires its resource upon creation and releases it upon destruction.
Definition RWTLockGuard.h:61
See also
RWMutexLock, RWTRecursiveLock

Member Typedef Documentation

◆ LockGuard

Predefined type for compatible guard.

◆ ReadLockGuard

Predefined type for compatible guard.

◆ ReadUnlockGuard

Predefined type for compatible guard.

◆ TryLockGuard

Predefined type for compatible guard.

◆ TryReadLockGuard

Predefined type for compatible guard.

◆ TryWriteLockGuard

Predefined type for compatible guard.

◆ UnlockGuard

Predefined type for compatible guard.

◆ WriteLockGuard

Predefined type for compatible guard.

◆ WriteUnlockGuard

Predefined type for compatible guard.

Constructor & Destructor Documentation

◆ RWFIFOMutexLock() [1/3]

RWFIFOMutexLock::RWFIFOMutexLock ( RWCancellationState state = 0)
inline

Creates and initializes an RWFIFOMutexLock. The thread cancellation state of the object is initialized to state.

◆ RWFIFOMutexLock() [2/3]

RWFIFOMutexLock::RWFIFOMutexLock ( RWStaticCtor )
inline

Constructs a static instance, but does no direct initialization. The RWFIFOMutexLock is initialized on first use.

This constructor must be used only for static instances. Use of this constructor with an automatically or dynamically allocated instance produces errors or other unpredictable behavior.

Static instances are zero initialized, which results in an RWFIFOMutexLock with cancellation state of RW_CANCELLATION_DISABLED.

Note
This constructor functions correctly only in single-threaded builds, due to the presence of some data members that do not implement a constructor with an RWStaticCtor argument.

◆ ~RWFIFOMutexLock()

RWFIFOMutexLock::~RWFIFOMutexLock ( )
inline

Recovers any system resources used to implement the RWFIFOMutexLock.

◆ RWFIFOMutexLock() [3/3]

RWFIFOMutexLock::RWFIFOMutexLock ( const RWFIFOMutexLock & second)
private

Copy construction prohibited.

Member Function Documentation

◆ acquire() [1/2]

void RWFIFOMutexLock::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 acquires the mutex and continues. Possible exceptions include RWCancellation and RWTHRInternalError.

In single-threaded builds, this method does not block. On success, it returns immediately; otherwise it fails with a debug assertion in debug mode, or a thrown RWTHRInternalError in release builds.

◆ acquire() [2/2]

RWWaitStatus RWFIFOMutexLock::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 immediately returns RW_THR_ACQUIRED if the resource is currently available, otherwise returns RW_THR_TIMEOUT.

◆ acquireRead() [1/2]

void RWFIFOMutexLock::acquireRead ( )
inline

Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

◆ acquireRead() [2/2]

RWWaitStatus RWFIFOMutexLock::acquireRead ( unsigned long milliseconds)
inline

Calls acquire(milliseconds). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

◆ acquireWrite() [1/2]

void RWFIFOMutexLock::acquireWrite ( )
inline

Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

◆ acquireWrite() [2/2]

RWWaitStatus RWFIFOMutexLock::acquireWrite ( unsigned long milliseconds)
inline

Calls acquire(milliseconds). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

◆ isAcquired()

bool RWFIFOMutexLock::isAcquired ( ) const

Determines whether the calling thread currently owns the mutex.

Condition:
Available only from the debug version of the Threads Module.

◆ operator=()

RWFIFOMutexLock & RWFIFOMutexLock::operator= ( const RWFIFOMutexLock & second)
private

Assignment prohibited.

◆ release()

void RWFIFOMutexLock::release ( )

Releases the mutex, making it available. Possible exceptions include RWTHRInternalError.

◆ tryAcquire()

bool RWFIFOMutexLock::tryAcquire ( )

Tries to acquire mutex without blocking. Returns true if successful, otherwise false. Possible exceptions include RWCancellation and RWTHRInternalError.

◆ tryAcquireRead()

bool RWFIFOMutexLock::tryAcquireRead ( )
inline

Calls tryAcquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

◆ tryAcquireWrite()

bool RWFIFOMutexLock::tryAcquireWrite ( )
inline

Calls tryAcquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.