ATLAS Offline Software
Loading...
Searching...
No Matches
LockedPointer.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 * Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
4 */
11
12
13#ifndef CXXUTILS_LOCKEDPOINTER_H
14#define CXXUTILS_LOCKEDPOINTER_H
15
16
17#include <mutex>
18
19
20namespace CxxUtils {
21
22
33template <class T, class MUTEX=std::recursive_mutex>
35{
36public:
37 LockedPointer (T& p, std::unique_lock<MUTEX>&& lock)
38 : m_lock (std::move (lock)),
39 m_p (p)
40 {
41 }
42
43 T* get() { return &m_p; }
44 T* operator->() { return &m_p; }
45 T& operator*() { return m_p; }
46
47private:
48 std::unique_lock<MUTEX> m_lock;
49 T& m_p;
50};
51
52} // namespace CxxUtils
53
54
55#endif // not CXXUTILS_LOCKEDPOINTER_H
std::unique_lock< std::recursive_mutex > m_lock
LockedPointer(T &p, std::unique_lock< MUTEX > &&lock)
STL namespace.