VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Protected Attributes | Private Member Functions
DtScopedLock Class Reference

DtScopedLock provides a Boost source compatible scoped lock for DtMutex. More...

+ Collaboration diagram for DtScopedLock:

Public Member Functions

 DtScopedLock (DtMutex &mx, bool initially_locked=true)
 Constructs a DtScopedLock on a mutex and conditionally locks that mutex. More...
 
 ~DtScopedLock ()
 Destructor, which will unlock if the mutex was locked. More...
 
void lock ()
 Lock the mutex. More...
 
void unlock ()
 Unlock the mutex. More...
 
bool locked () const
 
 operator const void * () const
 else null pointer. More...
 

Protected Attributes

DtMutexmyMutex
 
bool myLockedState
 

Private Member Functions

 DtScopedLock (const DtScopedLock &)
 Ensures non-copiable. More...
 
DtScopedLockoperator= (const DtScopedLock &)
 

Detailed Description

DtScopedLock provides a Boost source compatible scoped lock for DtMutex.

A DtScopedLock is a safe locking pattern for use in multi-threaded applications. DtScopedLock is non-copiable object, which should be created on the stack. The lock ensures that upon deallocation the lock is released.

DtMutex io_mutex;

* void threadSafe_printf(const char* string)
* {
* DtScopedLock lock(io_mutex);
* printf(string);
* }
*

Constructor & Destructor Documentation

DtScopedLock::DtScopedLock ( DtMutex mx,
bool  initially_locked = true 
)
explicit

Constructs a DtScopedLock on a mutex and conditionally locks that mutex.

DtScopedLock::~DtScopedLock ( )

Destructor, which will unlock if the mutex was locked.

DtScopedLock::DtScopedLock ( const DtScopedLock )
private

Ensures non-copiable.

Member Function Documentation

void DtScopedLock::lock ( )

Lock the mutex.

bool DtScopedLock::locked ( ) const
Returns
The locked state of the mutex.
Return values
trueThe mutex is locked.
falseThe mutex is unlocked.
DtScopedLock::operator const void * ( ) const

else null pointer.

DtScopedLock& DtScopedLock::operator= ( const DtScopedLock )
private
void DtScopedLock::unlock ( )

Unlock the mutex.

Member Data Documentation

bool DtScopedLock::myLockedState
protected
DtMutex& DtScopedLock::myMutex
protected

The documentation for this class was generated from the following file:

Document ID: Generated on Wed Mar 27 02:04:30 EDT 2024 from SVN revision 264570
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)