ATLAS Offline Software
threading.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-2024 CERN for the benefit of the ATLAS collaboration
4 */
17 #ifndef ATHCONTAINERS_THREADING_H
18 #define ATHCONTAINERS_THREADING_H
19 
20 
21 #ifdef ATHCONTAINERS_NO_THREADS
22 
23 
24 namespace AthContainers_detail {
25 
26 
30 class mutex {};
31 
32 
36 class recursive_mutex {};
37 
38 
42 template <class LOCKABLE>
43 class lock_guard
44 {
45 public:
46  lock_guard() {}
47  lock_guard(LOCKABLE&) {}
48 };
49 
50 
54 class upgrade_mutex
55 {
56 public:
57  void lock() {}
58  void unlock() {}
59  void lock_shared() {}
60  void unlock_shared() {}
61  void lock_upgrade() {}
62  void unlock_upgrade() {}
63  void unlock_upgrade_and_lock() {}
64 private:
65  // Real upgrade_mutex is not assignable. Need this for proper
66  // dictionary generation.
67  upgrade_mutex& operator= (const upgrade_mutex&);
68 };
69 
70 
74 template <class T>
75 class thread_specific_ptr
76 {
77 public:
78  thread_specific_ptr() : m_ptr(0) {}
79  ~thread_specific_ptr() { delete m_ptr; }
80  thread_specific_ptr (const thread_specific_ptr&) = delete;
81  thread_specific_ptr& operator= (const thread_specific_ptr&) = delete;
82  T* get() { return m_ptr; }
83  T* operator->() { return m_ptr; }
84  T& operator*() { return *m_ptr; }
85  const T* get() const { return m_ptr; }
86  const T* operator->() const { return m_ptr; }
87  const T& operator*() const { return *m_ptr; }
88  void reset (T* new_value=0) { delete m_ptr; m_ptr = new_value; }
89  T* release() { T* ret = m_ptr; m_ptr = 0; return ret; }
90 
91 private:
92  T* m_ptr;
93 };
94 
95 
97 inline void fence_acq_rel() {}
98 inline void fence_seq_cst() {}
99 
100 
102 template <class T>
103 class atomic
104 {
105 public:
106  atomic() : m_val() {}
107  operator T() const { return m_val; }
108  atomic& operator= (const T& val) { m_val = val; return *this; }
109 
110 private:
111  T m_val;
112 };
113 
114 
115 } // namespace AthContainers_detail
116 
117 
118 #else // not ATHCONTAINERS_NO_THREADS
119 
120 //the shared_mutex include generates annoying unused_variable warnings during compilations... silence this in athanalysisbase
121 #ifdef XAOD_ANALYSIS
122 #ifndef BOOST_SYSTEM_NO_DEPRECATED
123 #define BOOST_SYSTEM_NO_DEPRECATED 1
124 #endif
125 #endif
126 
127 #include "boost/thread/shared_mutex.hpp"
128 #include "boost/thread/tss.hpp"
129 
130 
131 #include <atomic>
132 #include <mutex>
133 #include <thread>
134 
135 
136 namespace AthContainers_detail {
137 
138 
139 // Take these from boost. (Boost extensions not in C++.)
140 using boost::upgrade_mutex;
141 using boost::thread_specific_ptr;
142 
143 using std::mutex;
144 using std::recursive_mutex;
145 using std::lock_guard;
146 using std::thread;
147 using std::atomic;
148 
149 
154 
155 
160 
161 
162 } // namespace AthContainers_detail
163 
164 
165 #endif // not ATHCONTAINERS_NO_THREADS
166 
167 
168 
169 namespace AthContainers_detail {
170 
171 
178 template <typename LOCKABLE>
180 {
181 public:
183  typedef LOCKABLE lockable_type;
184 
185 
191 
192 
198 
199 
204 
205 
206 private:
207  // Disallow these.
211 
212 
213 private:
216 };
217 
218 
227 template <class LOCKABLE>
229 {
230 public:
232  typedef LOCKABLE lockable_type;
233 
234 
240 
241 
246 
247 
251  void upgrade();
252 
253 
254 private:
255  // Disallow these.
259 
260 
261 private:
264 
267 };
268 
269 
270 } // namespace AthContainers_detail
271 
272 
274 
275 
276 #endif // not ATHCONTAINERS_THREADING_H
AthContainers_detail::fence_acq_rel
void fence_acq_rel()
An acquire/release fence.
AthContainers_detail::upgrading_lock::upgrading_lock
upgrading_lock(upgrading_lock const &)
AthContainers_detail::upgrading_lock::upgrading_lock
upgrading_lock()
AthContainers_detail::upgrading_lock::~upgrading_lock
~upgrading_lock()
Release the held lock.
AthContainers_detail::strict_shared_lock::strict_shared_lock
strict_shared_lock(const lockable_type &obj)
Take out a shared lock on obj and remember it.
AthContainers_detail::strict_shared_lock::strict_shared_lock
strict_shared_lock()
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
AthContainers_detail::upgrading_lock::upgrading_lock
upgrading_lock(lockable_type &obj)
Take out an upgrade lock on obj and remember it.
AthContainers_detail::strict_shared_lock::strict_shared_lock
strict_shared_lock(lockable_type &obj)
Take out a shared lock on obj and remember it.
AthContainers_detail::strict_shared_lock::strict_shared_lock
strict_shared_lock(strict_shared_lock const &)
AthContainers_detail::fence_seq_cst
void fence_seq_cst()
A sequentially-consistent fence.
AthContainers_detail
Definition: concurrent_vector.h:54
AthContainers_detail::strict_shared_lock::lockable_type
LOCKABLE lockable_type
The underlying object type.
Definition: threading.h:183
InDetDD::operator*
SiLocalPosition operator*(const SiLocalPosition &position, const double factor)
Definition: SiLocalPosition.cxx:98
AthContainers_detail::strict_shared_lock
Lock object for taking out shared locks.
Definition: threading.h:180
AthContainers_detail::upgrading_lock::upgrade
void upgrade()
Convert the lock from upgrade to exclusive.
AthContainers_detail::strict_shared_lock::~strict_shared_lock
~strict_shared_lock()
Release the held lock.
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
AthContainers_detail::upgrading_lock::operator=
upgrading_lock & operator=(upgrading_lock const &)
AthContainers_detail::upgrading_lock::lockable_type
LOCKABLE lockable_type
The underlying object type.
Definition: threading.h:232
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::reset
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Definition: bitmask.h:251
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
AthContainers_detail::upgrading_lock::m_obj
lockable_type & m_obj
The lock being held.
Definition: threading.h:263
AthContainers_detail::upgrading_lock
Lock object for taking out upgradable locks.
Definition: threading.h:229
AthContainers_detail::strict_shared_lock::m_obj
lockable_type & m_obj
The lock being held.
Definition: threading.h:215
python.PyAthena.obj
obj
Definition: PyAthena.py:132
AthContainers_detail::upgrading_lock::m_exclusive
bool m_exclusive
Has the lock been converted to exclusive?
Definition: threading.h:266
AthContainers_detail::strict_shared_lock::operator=
strict_shared_lock & operator=(strict_shared_lock const &)
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
threading.icc