ATLAS Offline Software
Loading...
Searching...
No Matches
CxxUtils::LockedPointer< T, MUTEX > Class Template Reference

A pointer together with a movable lock. More...

#include <LockedPointer.h>

Collaboration diagram for CxxUtils::LockedPointer< T, MUTEX >:

Public Member Functions

 LockedPointer (T &p, std::unique_lock< MUTEX > &&lock)
T * get ()
T * operator-> ()
T & operator* ()

Private Attributes

std::unique_lock< MUTEX > m_lock
T & m_p

Detailed Description

template<class T, class MUTEX = std::recursive_mutex>
class CxxUtils::LockedPointer< T, MUTEX >

A pointer together with a movable lock.

This class holds a pointer to T along with a unique_lock. It can be used where we want to return a pointer to an object protected by a lock, and so want to return the lock along with the pointer.

Objects of this class may be moved but not copied (like unique_ptr).

Definition at line 34 of file LockedPointer.h.

Constructor & Destructor Documentation

◆ LockedPointer()

template<class T, class MUTEX = std::recursive_mutex>
CxxUtils::LockedPointer< T, MUTEX >::LockedPointer ( T & p,
std::unique_lock< MUTEX > && lock )
inline

Definition at line 37 of file LockedPointer.h.

38 : m_lock (std::move (lock)),
39 m_p (p)
40 {
41 }
A pointer together with a movable lock.
std::unique_lock< MUTEX > m_lock

Member Function Documentation

◆ get()

template<class T, class MUTEX = std::recursive_mutex>
T * CxxUtils::LockedPointer< T, MUTEX >::get ( )
inline

Definition at line 43 of file LockedPointer.h.

43{ return &m_p; }

◆ operator*()

template<class T, class MUTEX = std::recursive_mutex>
T & CxxUtils::LockedPointer< T, MUTEX >::operator* ( )
inline

Definition at line 45 of file LockedPointer.h.

45{ return m_p; }

◆ operator->()

template<class T, class MUTEX = std::recursive_mutex>
T * CxxUtils::LockedPointer< T, MUTEX >::operator-> ( )
inline

Definition at line 44 of file LockedPointer.h.

44{ return &m_p; }

Member Data Documentation

◆ m_lock

template<class T, class MUTEX = std::recursive_mutex>
std::unique_lock<MUTEX> CxxUtils::LockedPointer< T, MUTEX >::m_lock
private

Definition at line 48 of file LockedPointer.h.

◆ m_p

template<class T, class MUTEX = std::recursive_mutex>
T& CxxUtils::LockedPointer< T, MUTEX >::m_p
private

Definition at line 49 of file LockedPointer.h.


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