UT_DoubleLock< T > Class Template Reference

#include <UT_DoubleLock.h>

List of all members.

Public Member Functions

 UT_DoubleLock (UT_Lock &lock, T &val)
 ~UT_DoubleLock ()
getValue ()
void setValue (T val)


Detailed Description

template<class T>
class UT_DoubleLock< T >

A double-checked lock. Only locks the thread lock when the value is 0.

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.


Constructor & Destructor Documentation

template<class T >
UT_DoubleLock< T >::UT_DoubleLock ( UT_Lock lock,
T &  val 
) [inline]

Definition at line 65 of file UT_DoubleLock.h.

template<class T >
UT_DoubleLock< T >::~UT_DoubleLock (  )  [inline]

Definition at line 81 of file UT_DoubleLock.h.


Member Function Documentation

template<class T >
T UT_DoubleLock< T >::getValue (  )  [inline]

Definition at line 94 of file UT_DoubleLock.h.

template<class T >
void UT_DoubleLock< T >::setValue ( val  )  [inline]

Definition at line 100 of file UT_DoubleLock.h.


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

Generated on Mon Jan 28 00:49:02 2013 for HDK by  doxygen 1.5.9