HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_DoubleLock< ValueT, LockT > Class Template Reference

#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 ()
 

Detailed Description

template<typename ValueT, typename LockT = UT_Lock>
class UT_DoubleLock< ValueT, LockT >

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.

Examples:
packedshareddata/GU_PackedSharedData.C.

Definition at line 50 of file UT_DoubleLock.h.

Member Typedef Documentation

template<typename ValueT, typename LockT = UT_Lock>
using UT_DoubleLock< ValueT, LockT >::GetT = typename TraitT::GetT

Definition at line 59 of file UT_DoubleLock.h.

template<typename ValueT, typename LockT = UT_Lock>
using UT_DoubleLock< ValueT, LockT >::SetT = typename TraitT::SetT

Definition at line 60 of file UT_DoubleLock.h.

Constructor & Destructor Documentation

template<typename ValueT, typename LockT = UT_Lock>
UT_DoubleLock< ValueT, LockT >::UT_DoubleLock ( LockT &  lock,
volatile ValueT &  val 
)
inline

Definition at line 63 of file UT_DoubleLock.h.

template<typename ValueT, typename LockT = UT_Lock>
UT_DoubleLock< ValueT, LockT >::~UT_DoubleLock ( )
inline

Definition at line 79 of file UT_DoubleLock.h.

Member Function Documentation

template<typename ValueT, typename LockT = UT_Lock>
void UT_DoubleLock< ValueT, LockT >::abort ( )
inline

Abort writing back out to the val passed in the constructor upon destruction.

Definition at line 131 of file UT_DoubleLock.h.

template<typename ValueT, typename LockT = UT_Lock>
GetT UT_DoubleLock< ValueT, LockT >::getValue ( ) const
inline

Definition at line 106 of file UT_DoubleLock.h.

template<typename ValueT, typename LockT = UT_Lock>
void UT_DoubleLock< ValueT, LockT >::setValue ( SetT  val)
inline

Definition at line 123 of file UT_DoubleLock.h.


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