| The Gaudi Framework v32r1 (f65d50dc)

Classes | Public Member Functions | Private Attributes | List of all members
LockedHandle< T, MutexType > Class Template Reference

Provides automatic lock/unlock access to a class upon deref of ptr. More...

`#include <GaudiKernel/LockedHandle.h>`

## Classes
class | ConstGuard
class | Guard

## Public Member Functions
| LockedHandle (T *ptr, MutexType &mut)
| LockedHandle (T *ptr, MutexType *mut)
| LockedHandle (T *ptr)
| LockedHandle ()
void | set (T *ptr, MutexType *mut)
void | setMutex (MutexType *mut)
T * | get () const
Guard | operator * ()
| Aquire and release the lock before and after the object is accessed. More...
Guard | operator-> ()
| Aquire and release the lock before and after the object is accessed. More...
ConstGuard | operator * () const
| Aquire and release the lock before and after the const object is accessed. More...
ConstGuard | operator-> () const
| Aquire and release the lock before and after the const object is accessed. More...
| operator bool () const

## Private Attributes
T * | m_ptr
MutexType * | m_mutex

## Detailed Description

### template<class T, class MutexType = std::mutex>
class LockedHandle< T, MutexType >

Provides automatic lock/unlock access to a class upon deref of ptr.

default type of mutex to use is a std::mutex, but this can be overridden with a second template parameter, as long as the type provides the lock() and unlock() functions

std::mutex the_mutex;
Obj *o = new Obj();
LockedHandle<Obj> lh(o, &the_mutex);
o->doSomething();

Author
  Charles Leggett / Goetz Gaycken

Date
  2016-07-01

Definition at line 28 of file LockedHandle.h.

## Constructor & Destructor Documentation

## ◆ LockedHandle() [1/4]

template<class T, class MutexType = std::mutex>

LockedHandle< T, MutexType >::LockedHandle | ( | T * | ptr,
|  | MutexType & | mut
| ) |  |
| inline

Definition at line 30 of file LockedHandle.h.

30 : m_ptr( ptr ), m_mutex( &mut ) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ LockedHandle() [2/4]

template<class T, class MutexType = std::mutex>

LockedHandle< T, MutexType >::LockedHandle | ( | T * | ptr,
|  | MutexType * | mut
| ) |  |
| inline

Definition at line 31 of file LockedHandle.h.

31 : m_ptr( ptr ), m_mutex( mut ) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ LockedHandle() [3/4]

template<class T, class MutexType = std::mutex>

LockedHandle< T, MutexType >::LockedHandle | ( | T * | ptr | ) |
| inline

Definition at line 32 of file LockedHandle.h.

32 : m_ptr( ptr ), m_mutex( 0 ) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ LockedHandle() [4/4]

template<class T, class MutexType = std::mutex>

LockedHandle< T, MutexType >::LockedHandle | ( |  | ) |
| inline

Definition at line 33 of file LockedHandle.h.

33 : m_ptr( nullptr ), m_mutex( nullptr ) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## Member Function Documentation

## ◆ get()

template<class T, class MutexType = std::mutex>

T* LockedHandle< T, MutexType >::get | ( |  | ) | const
| inline

Definition at line 42 of file LockedHandle.h.

42 { return m_ptr; }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95

## ◆ operator *() [1/2]

template<class T, class MutexType = std::mutex>

Guard LockedHandle< T, MutexType >::operator * | ( |  | ) |
| inline

Aquire and release the lock before and after the object is accessed.

Definition at line 81 of file LockedHandle.h.

81 { return Guard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ operator *() [2/2]

template<class T, class MutexType = std::mutex>

ConstGuard LockedHandle< T, MutexType >::operator * | ( |  | ) | const
| inline

Aquire and release the lock before and after the const object is accessed.

Definition at line 87 of file LockedHandle.h.

87 { return ConstGuard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ operator bool()

template<class T, class MutexType = std::mutex>

LockedHandle< T, MutexType >::operator bool | ( |  | ) | const
| inline

Definition at line 92 of file LockedHandle.h.

92 { return m_ptr; }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95

## ◆ operator->() [1/2]

template<class T, class MutexType = std::mutex>

Guard LockedHandle< T, MutexType >::operator-> | ( |  | ) |
| inline

Aquire and release the lock before and after the object is accessed.

Definition at line 84 of file LockedHandle.h.

84 { return Guard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ operator->() [2/2]

template<class T, class MutexType = std::mutex>

ConstGuard LockedHandle< T, MutexType >::operator-> | ( |  | ) | const
| inline

Aquire and release the lock before and after the const object is accessed.

Definition at line 90 of file LockedHandle.h.

90 { return ConstGuard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ set()

template<class T, class MutexType = std::mutex>

void LockedHandle< T, MutexType >::set | ( | T * | ptr,
|  | MutexType * | mut
| ) |  |
| inline

Definition at line 35 of file LockedHandle.h.

35 {
36 m_ptr = ptr;
37 m_mutex = mut;
38 }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:95
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## ◆ setMutex()

template<class T, class MutexType = std::mutex>

void LockedHandle< T, MutexType >::setMutex | ( | MutexType * | mut | ) |
| inline

Definition at line 40 of file LockedHandle.h.

40 { m_mutex = mut; }
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:96

## Member Data Documentation

## ◆ m_mutex

template<class T, class MutexType = std::mutex>

MutexType* LockedHandle< T, MutexType >::m_mutex
| mutable private

Definition at line 96 of file LockedHandle.h.

## ◆ m_ptr

template<class T, class MutexType = std::mutex>

T* LockedHandle< T, MutexType >::m_ptr
| private

Definition at line 95 of file LockedHandle.h.

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

- GaudiKernel/GaudiKernel/LockedHandle.h