rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWNullMutexLock Class Reference
[Synchronization]

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

#include <rw/sync/RWNullMutexLock.h>

Inheritance diagram for RWNullMutexLock:
RWSynchObject

List of all members.

Public Types

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

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 ()

Private Member Functions

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

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<Mutex> .

Examples

 #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
 }
See also:
RWMutexLock, RWTLockGuard<Resource>, RWTUnlockGuard<Resource>, RWTTryLockGuard<Resource>

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

RWWaitStatus RWNullMutexLock::acquire ( unsigned long  milliseconds  )  [inline]

Returns RW_THR_ACQUIRED.

void RWNullMutexLock::acquire ( void   )  [inline]

Does nothing.

RWWaitStatus RWNullMutexLock::acquireRead ( unsigned long  milliseconds  )  [inline]

Returns RW_THR_ACQUIRED.

void RWNullMutexLock::acquireRead (  )  [inline]

Does nothing.

RWWaitStatus RWNullMutexLock::acquireWrite ( unsigned long  milliseconds  )  [inline]

Returns RW_THR_ACQUIRED.

void RWNullMutexLock::acquireWrite (  )  [inline]

Does nothing.

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.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© 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.