VR-Link API Documentation for HLA 1516
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:

List of all members.

Public Member Functions

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

Protected Attributes

DtMutexmyMutex
bool myLockedState

Private Member Functions

 DtScopedLock (const DtScopedLock &)
 Ensures non-copiable.
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.

Destructor, which will unlock if the mutex was locked.

DtScopedLock::DtScopedLock ( const DtScopedLock ) [private]

Ensures non-copiable.


Member Function Documentation

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]

Unlock the mutex.


Member Data Documentation

bool DtScopedLock::myLockedState [protected]

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

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)