SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (RWCancellationState state=0)
 
 RWNullMutexLock (RWStaticCtor)
 
 ~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 (const RWSynchObject &second)
 
 RWSynchObject (RWCancellationState state=0)
 
 RWSynchObject (RWStaticCtor)
 
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
}
}
Efficient stand-in for a mutual exclusion lock when synchronization is either unnecessary or not impo...
Definition RWNullMutexLock.h:74
void release()
Definition RWNullMutexLock.h:272
void acquire()
Definition RWNullMutexLock.h:242
See also
RWMutexLock, RWTLockGuard, RWTUnlockGuard, RWTTryLockGuard

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

◆ RWNullMutexLock() [1/3]

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() [2/3]

RWNullMutexLock::RWNullMutexLock ( RWCancellationState state = 0)
inline

Creates an RWNullMutexLock. The parameter state is currently ignored.

◆ ~RWNullMutexLock()

RWNullMutexLock::~RWNullMutexLock ( )
inline

Destructor.

◆ RWNullMutexLock() [3/3]

RWNullMutexLock::RWNullMutexLock ( const RWNullMutexLock & second)
private

Copy construction prohibited.

Member Function Documentation

◆ acquire() [1/2]

void RWNullMutexLock::acquire ( )
inline

Does nothing.

◆ acquire() [2/2]

RWWaitStatus RWNullMutexLock::acquire ( unsigned long milliseconds)
inline

Returns RW_THR_ACQUIRED.

◆ acquireRead() [1/2]

void RWNullMutexLock::acquireRead ( )
inline

Does nothing.

◆ acquireRead() [2/2]

RWWaitStatus RWNullMutexLock::acquireRead ( unsigned long milliseconds)
inline

Returns RW_THR_ACQUIRED.

◆ acquireWrite() [1/2]

void RWNullMutexLock::acquireWrite ( )
inline

Does nothing.

◆ acquireWrite() [2/2]

RWWaitStatus RWNullMutexLock::acquireWrite ( unsigned long milliseconds)
inline

Returns RW_THR_ACQUIRED.

◆ isAcquired()

bool RWNullMutexLock::isAcquired ( ) const

Returns true.

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

◆ operator=()

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

Assignment prohibited.

◆ release()

void RWNullMutexLock::release ( )
inline

Does nothing.

◆ tryAcquire()

bool RWNullMutexLock::tryAcquire ( )
inline

Returns true.

◆ tryAcquireRead()

bool RWNullMutexLock::tryAcquireRead ( )
inline

Returns true.

◆ tryAcquireWrite()

bool RWNullMutexLock::tryAcquireWrite ( )
inline

Returns true.

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