| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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 30 of file LockedHandle.h.

## Constructor & Destructor Documentation

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

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

Definition at line 33 of file LockedHandle.h.

33 : m_ptr(ptr), m_mutex(&mut) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
template<class T, class MutexType = std::mutex>

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

Definition at line 34 of file LockedHandle.h.

34 : m_ptr(ptr), m_mutex(mut) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
template<class T, class MutexType = std::mutex>

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

Definition at line 35 of file LockedHandle.h.

35 : m_ptr(ptr), m_mutex(0) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
template<class T, class MutexType = std::mutex>

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

Definition at line 36 of file LockedHandle.h.

36 : m_ptr(nullptr), m_mutex(nullptr) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128

## Member Function Documentation

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

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

Definition at line 45 of file LockedHandle.h.

45 { return m_ptr; }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
template<class T, class MutexType = std::mutex>

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

Definition at line 122 of file LockedHandle.h.

122 {
123 return m_ptr;
124 }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
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 111 of file LockedHandle.h.

111 { return Guard(m_ptr,*m_mutex); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
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 117 of file LockedHandle.h.

117 { return ConstGuard(m_ptr,*m_mutex); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
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 114 of file LockedHandle.h.

114 { return Guard(m_ptr,*m_mutex); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
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 120 of file LockedHandle.h.

120 { return ConstGuard(m_ptr,*m_mutex); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
template<class T, class MutexType = std::mutex>

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

Definition at line 38 of file LockedHandle.h.

38 {
39 m_ptr = ptr;
40 m_mutex = mut;
41 }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:127
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128
template<class T, class MutexType = std::mutex>

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

Definition at line 43 of file LockedHandle.h.

43 { m_mutex = mut; }
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:128

## Member Data Documentation

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

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

Definition at line 128 of file LockedHandle.h.

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

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

Definition at line 127 of file LockedHandle.h.

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

- GaudiKernel/GaudiKernel/LockedHandle.h