SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions | Private Member Functions
RWNullMutexLock Class Reference

Efficient stand-in for a mutual exclusion lock when synchronization is either unnecessary or not important. More...

#include <rw/sync/RWNullMutexLock.h>

Inheritance diagram for RWNullMutexLock:
RWSynchObject

Public Types

typedef RWTLockGuard< RWNullMutexLockLockGuard
 
typedef RWTReadLockGuard< RWNullMutexLockReadLockGuard
 
typedef RWTReadUnlockGuard< RWNullMutexLockReadUnlockGuard
 
typedef RWTTryLockGuard< RWNullMutexLockTryLockGuard
 
typedef RWTTryReadLockGuard< RWNullMutexLockTryReadLockGuard
 
typedef RWTTryWriteLockGuard< RWNullMutexLockTryWriteLockGuard
 
typedef RWTUnlockGuard< RWNullMutexLockUnlockGuard
 
typedef RWTWriteLockGuard< RWNullMutexLockWriteLockGuard
 
typedef RWTWriteUnlockGuard< RWNullMutexLockWriteUnlockGuard
 

Public Member Functions

 RWNullMutexLock (RWStaticCtor)
 
 RWNullMutexLock (RWCancellationState state=0)
 
 ~RWNullMutexLock ()
 
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

 RWNullMutexLock (const RWNullMutexLock &second)
 
RWNullMutexLockoperator= (const RWNullMutexLock &second)
 

Additional Inherited Members

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

Detailed Description

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 the template classes that accept a mutex parameter, such as RWTMonitor.

Example
#include <rw/sync/RWMutexLock.h>
#include <rw/sync/RWNullMutexLock.h>
int main()
{
mutex.acquire(); // No cost if synchronization not required
// critical section
mutex.release();
// Same thing, this time using a guard:
{
RWNullMutexLock::Lockguard lock(mutex); // does nothing if
// synchronization not
// required critical section
// If synchronization required, lock will be released
// automatically
}
}
See also
RWMutexLock, RWTLockGuard, RWTUnlockGuard, RWTTryLockGuard

Member Typedef Documentation

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Constructor & Destructor Documentation

RWNullMutexLock::RWNullMutexLock ( RWStaticCtor  )
inline

Constructs a static instance, but does no direct initialization. The RWNullMutexLock 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 RWNullMutexLock with a cancellation state of RW_CANCELLATION_DISABLED.

RWNullMutexLock::RWNullMutexLock ( RWCancellationState  state = 0)
inline

Creates an RWNullMutexLock. The parameter state is currently ignored.

RWNullMutexLock::~RWNullMutexLock ( )
inline

Destructor.

RWNullMutexLock::RWNullMutexLock ( const RWNullMutexLock second)
private

Copy construction prohibited.

Member Function Documentation

void RWNullMutexLock::acquire ( void  )
inline

Does nothing.

RWWaitStatus RWNullMutexLock::acquire ( unsigned long  milliseconds)
inline

Returns RW_THR_ACQUIRED.

void RWNullMutexLock::acquireRead ( )
inline

Does nothing.

RWWaitStatus RWNullMutexLock::acquireRead ( unsigned long  milliseconds)
inline

Returns RW_THR_ACQUIRED.

void RWNullMutexLock::acquireWrite ( )
inline

Does nothing.

RWWaitStatus RWNullMutexLock::acquireWrite ( unsigned long  milliseconds)
inline

Returns RW_THR_ACQUIRED.

bool RWNullMutexLock::isAcquired ( ) const

Returns true.

Condition:
Available only from the debug version of the Threads Module.
RWNullMutexLock& RWNullMutexLock::operator= ( const RWNullMutexLock second)
private

Assignment prohibited.

void RWNullMutexLock::release ( void  )
inline

Does nothing.

bool RWNullMutexLock::tryAcquire ( )
inline

Returns true.

bool RWNullMutexLock::tryAcquireRead ( )
inline

Returns true.

bool RWNullMutexLock::tryAcquireWrite ( )
inline

Returns true.

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