#include <UT_DoubleLock.h>
Public Member Functions | |
| UT_DoubleLock (UT_Lock &lock, T &val) | |
| ~UT_DoubleLock () | |
| T | getValue () |
| void | setValue (T val) |
This works similar to an AutoLock, but provides a needInit function to tell you if you val was false after locking
To use this lock:
static UT_Lock theLock; static OBJECT *theObj = 0;
OBJECT * getSingleton() { UT_DoubleLock<OBJECT *> lock(theLock, theObj);
if (!lock.getValue()) { lock.setValue(new OBJECT()); } return lock.getValue(); }
NOTE: Do not roll your own double checked lock. Double checked locks ideally need machine support to work properly - this implementation is theoretically broken. The intent of this class is to make it easy to replace DoubleLock with an AutoLock equivalent, allowing us to time the cost of using AutoLocks and see if one of these odd cases is the source of multi threaded bugs.
You are discouraged from using double checked locks. Consider eager evaluation or thread local storage of the cached value as preferable alternatives.
Definition at line 62 of file UT_DoubleLock.h.
| UT_DoubleLock< T >::UT_DoubleLock | ( | UT_Lock & | lock, | |
| T & | val | |||
| ) | [inline] |
Definition at line 65 of file UT_DoubleLock.h.
| UT_DoubleLock< T >::~UT_DoubleLock | ( | ) | [inline] |
Definition at line 81 of file UT_DoubleLock.h.
| T UT_DoubleLock< T >::getValue | ( | ) | [inline] |
Definition at line 94 of file UT_DoubleLock.h.
| void UT_DoubleLock< T >::setValue | ( | T | val | ) | [inline] |
Definition at line 100 of file UT_DoubleLock.h.
1.5.9