Difference between revisions of "CXScopeLock"
From cxwiki
(Created page with "<div class="mw-parser-output">The CXScopeLock template class is intended to be constructed on the stack as a mechanism to take a lock and ensure that it is released again...") |
|||
Line 25: | Line 25: | ||
= Restrictions = | = Restrictions = | ||
− | The template parameter must be a lock type with the same interface as [[CXMutex]]. This includes [[CXRecursiveMutex]] and [[CXSpinLock]] but not [[CXReadWriteLock]]. A separate [[CXScopeLockReadWrite]] is available. | + | The template parameter must be a lock type with the same interface as [[CXMutex|CXMutex]]. This includes [[CXRecursiveMutex|CXRecursiveMutex]] and [[CXSpinLock|CXSpinLock]] but not [[CXReadWriteLock|CXReadWriteLock]]. A separate [[CXScopeLockReadWrite|CXScopeLockReadWrite]] is available. |
</div> <div class="mw-parser-output"> </div> | </div> <div class="mw-parser-output"> </div> |
Latest revision as of 23:47, 22 February 2018
The CXScopeLock template class is intended to be constructed on the stack as a mechanism to take a lock and ensure that it is released again when the CXScopeLock object goes out of scope. This is intended as a way to reduce manual lock management errors.
// Construct a CXScopeLock object, taking a lock on the specified mutex.
CXScopeLock(const T& mutex);
// Construct a CXScopeLock object, optionally taking a lock on the specified mutex.
CXScopeLock(const T& mutex, bool bShouldTakeLock);
// Destruct a CXScopeLock object, releasing any outstanding lock held by this
// object.
~CXScopeLock(void);
// Take a lock on the specified mutex. This is a no-op if the specified mutex is
// already locked. This results in any outstanding mutex lock held by this object
// being releasing first.
void Lock(const T& mutex);
// Unlock any outstanding lock held by this object.
void Unlock(void);
// Detach from any outstanding locks without releasing them. It is the
// responsibility of the caller to determine whether anything was locked and
// release that lock when necessary.
void Detach(void);
Restrictions
The template parameter must be a lock type with the same interface as CXMutex. This includes CXRecursiveMutex and CXSpinLock but not CXReadWriteLock. A separate CXScopeLockReadWrite is available.