HDK
|
#include <UT_DoubleLock.h>
Public Member Functions | |
UT_DoubleLock (LOCK_T &lock, volatile T &val) | |
~UT_DoubleLock () | |
T | getValue () |
void | setValue (T 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.
|
inline |
Definition at line 53 of file UT_DoubleLock.h.
|
inline |
Definition at line 69 of file UT_DoubleLock.h.
|
inline |
Abort writing back out to the val passed in the constructor upon destruction.
Definition at line 120 of file UT_DoubleLock.h.
|
inline |
Definition at line 94 of file UT_DoubleLock.h.
|
inline |
Definition at line 112 of file UT_DoubleLock.h.