| The Gaudi Framework v29r1 (5cd95fa2)

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

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

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

Definition at line 32 of file LockedHandle.h.

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

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

Definition at line 33 of file LockedHandle.h.

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

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

Definition at line 34 of file LockedHandle.h.

34 : m_ptr( nullptr ), m_mutex( nullptr ) {}
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:99
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:100

## Member Function Documentation

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

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

Definition at line 44 of file LockedHandle.h.

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

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

Definition at line 96 of file LockedHandle.h.

96 { return m_ptr; }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:99
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 85 of file LockedHandle.h.

85 { return Guard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:99
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:100
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 91 of file LockedHandle.h.

91 { return ConstGuard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:99
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:100
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 88 of file LockedHandle.h.

88 { return Guard( m_ptr, *m_mutex ); }
LockedHandle::m_ptr
T * m_ptr
Definition: LockedHandle.h:99
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:100
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 94 of file LockedHandle.h.

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

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

Definition at line 36 of file LockedHandle.h.

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

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

Definition at line 42 of file LockedHandle.h.

42 { m_mutex = mut; }
LockedHandle::m_mutex
MutexType * m_mutex
Definition: LockedHandle.h:100

## Member Data Documentation

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

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

Definition at line 100 of file LockedHandle.h.

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

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

Definition at line 99 of file LockedHandle.h.

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

- GaudiKernel/GaudiKernel/LockedHandle.h