SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Provides mutual exclusion for a critical section of code in which only one thread should execute at a time. More...
#include <rw/sync/RWCriticalSection.h>
Public Types | |
typedef RWTLockGuard < RWCriticalSection > | LockGuard |
typedef RWTLockGuard < RWCriticalSection > | ReadLockGuard |
typedef RWTLockGuard < RWCriticalSection > | WriteLockGuard |
typedef RWTUnlockGuard < RWCriticalSection > | UnlockGuard |
typedef RWTUnlockGuard < RWCriticalSection > | ReadUnlockGuard |
typedef RWTUnlockGuard < RWCriticalSection > | WriteUnlockGuard |
Public Member Functions | |
RWCriticalSection (RWStaticCtor) | |
RWCriticalSection (RWCancellationState state=0) | |
~RWCriticalSection () | |
RWCriticalSectionRep * | getCriticalSectionRep () const |
void | acquire () |
void | release () |
void | acquireRead () |
void | acquireWrite () |
Private Member Functions | |
RWCriticalSection (const RWCriticalSection &) | |
RWCriticalSection & | operator= (const RWCriticalSection &) |
Related Functions | |
(Note that these are not member functions.) | |
typedef RWMutexLock | RWCriticalSectionRep |
typedef RWMutexType | RWCriticalSectionRep |
An RWCriticalSection object is used to provide mutual exclusion for a critical section of code, i.e. code in which only one thread should execute at a time. This lock operates in a manner that is identical to RWMutexLock except that on certain platforms, for example Win32, it may yield superior performance when there is minimal contention for the lock.
#include <rw/sync/RWCriticalSection.h> void foo () { static RWCriticalSection outputCritsec(RW_STATIC_CTOR); // ... int i; // ... // Protect output from multiple threads // using cout at the same time: outputCritsec.acquire (); std::cout << "The value of i is " << i << std::endl; outputCritsec.release (); // Same thing, this time using a guard: { RWCriticalSection::LockGuard lock (outputCritsec); std::cout << "The value of i is " << i << std::endl; } }
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.
RWCriticalSection::RWCriticalSection | ( | RWStaticCtor | ) | [inline] |
Constructs a static instance, but does no direct initialization. The RWCriticalSection is initialized on first use.
This constructor must be used only for static instances. Use of this constructor with automatically or dynamically allocated instances produces errors or other unpredictable behavior.
Static instances are zero initialized, which results in an RWCriticalSection with cancellation state of RW_CANCELLATION_DISABLED.
RWCriticalSection::RWCriticalSection | ( | RWCancellationState | state = 0 |
) | [inline] |
Creates and initializes the critical section. Possible exceptions include RWTHRInternalError.
RWCriticalSection::~RWCriticalSection | ( | ) | [inline] |
Default destructor.
RWCriticalSection::RWCriticalSection | ( | const RWCriticalSection & | ) | [private] |
Copy construction prohibited.
void RWCriticalSection::acquire | ( | void | ) | [inline] |
Blocks until the critical section is available. Possible exceptions include RWCancellation and RWTHRInternalError.
In single-threaded builds, this method returns immediately. If the section is unavailable, a debug assertion will occur, or an RWTHRInternalError will be thrown.
void RWCriticalSection::acquireRead | ( | ) | [inline] |
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
void RWCriticalSection::acquireWrite | ( | ) | [inline] |
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
RWCriticalSectionRep * RWCriticalSection::getCriticalSectionRep | ( | ) | const [inline] |
Provides access to the underlying platform-specific critical section implementation.
RWCriticalSection& RWCriticalSection::operator= | ( | const RWCriticalSection & | ) | [private] |
Assignment prohibited.
void RWCriticalSection::release | ( | void | ) | [inline] |
Releases the critical section. Possible exceptions include RWTHRInternalError.
typedef RWMutexType RWCriticalSectionRep [related] |
Typedef for the internal critical section.
typedef RWMutexLock RWCriticalSectionRep [related] |
Typedef for the internal critical section.
© 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.