HDK
|
#include <UT_DoubleLock.h>
Public Types | |
using | GetT = typename TraitT::GetT |
using | SetT = typename TraitT::SetT |
Public Member Functions | |
UT_DoubleLock (LockT &lock, volatile ValueT &val) | |
~UT_DoubleLock () | |
GetT | getValue () const |
void | setValue (SetT val) |
void | abort () |
A double-checked lock. Only locks the thread lock when the value is 0.
To use this lock:
static UT_Lock theLock; static OBJECT *theObj = 0;
OBJECT * getSingleton() { UT_DoubleLock<OBJECT *> lock(theLock, theObj);
if (!lock.getValue()) { // NOTE: This doesn't set theObj. theObj is set when // destructing lock. lock.setValue(new OBJECT()); } return lock.getValue(); }
NOTE: DO NOT roll your own double checked lock! If you don't know when to use which memory fences and why, odds are high that your custom implementation will be thread-unsafe.
For simple singleton initialization, consider using UT_Singleton.
Definition at line 50 of file UT_DoubleLock.h.
using UT_DoubleLock< ValueT, LockT >::GetT = typename TraitT::GetT |
Definition at line 59 of file UT_DoubleLock.h.
using UT_DoubleLock< ValueT, LockT >::SetT = typename TraitT::SetT |
Definition at line 60 of file UT_DoubleLock.h.
|
inline |
Definition at line 63 of file UT_DoubleLock.h.
|
inline |
Definition at line 79 of file UT_DoubleLock.h.
|
inline |
Abort writing back out to the val passed in the constructor upon destruction.
Definition at line 131 of file UT_DoubleLock.h.
|
inline |
Definition at line 106 of file UT_DoubleLock.h.
|
inline |
Definition at line 123 of file UT_DoubleLock.h.