ATLAS Offline Software
Loading...
Searching...
No Matches
threading.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id$
6/**
7 * @file AthContainers/tools.threading.icc
8 * @author scott snyder <snyder@bnl.gov>
9 * @date Sep, 2013
10 * @brief Threading definitions.
11 */
12
13
14namespace AthContainers_detail {
15
16
17#ifndef ATHCONTAINERS_NO_THREADS
18
19
20/**
21 * @brief An acquire/release fence.
22 */
23inline
24void fence_acq_rel()
25{
26 std::atomic_thread_fence (std::memory_order_acq_rel);
27}
28
29
30/**
31 * @brief A sequentially-consistent fence.
32 */
33inline
34void fence_seq_cst()
35{
36 std::atomic_thread_fence (std::memory_order_seq_cst);
37}
38
39
40#endif
41
42
43/**
44 * @brief Take out a shared lock on @c obj and remember it.
45 * @param obj The lockable object.
46 */
47template <typename LOCKABLE>
48inline
49strict_shared_lock<LOCKABLE>::strict_shared_lock (lockable_type& obj)
50 : m_obj(obj)
51{
52 obj.lock_shared(); // locks on construction
53}
54
55
56/**
57 * @brief Take out a shared lock on @c obj and remember it.
58 * @param obj The lockable object.
59 */
60template <typename LOCKABLE>
61inline
62strict_shared_lock<LOCKABLE>::strict_shared_lock (const lockable_type& obj)
63 : m_obj(const_cast<lockable_type&>(obj))
64{
65 obj.lock_shared(); // locks on construction
66}
67
68
69/**
70 * @brief Release the held lock.
71 */
72template <typename LOCKABLE>
73inline
74strict_shared_lock<LOCKABLE>::~strict_shared_lock()
75{
76 m_obj.unlock_shared(); // unlocks on destruction
77}
78
79
80/**
81 * @brief Take out an upgrade lock on @c obj and remember it.
82 * @param obj The lockable object.
83 */
84template <typename LOCKABLE>
85inline
86upgrading_lock<LOCKABLE>::upgrading_lock (lockable_type& obj)
87 : m_obj (obj)
88{
89 m_obj.lock_upgrade();
90 m_exclusive = false;
91}
92
93
94/**
95 * @brief Release the held lock.
96 */
97template <typename LOCKABLE>
98inline
99upgrading_lock<LOCKABLE>::~upgrading_lock()
100{
101 if (m_exclusive)
102 m_obj.unlock();
103 else
104 m_obj.unlock_upgrade();
105}
106
107
108/**
109 * @brief Convert the lock from upgrade to exclusive.
110 */
111template <typename LOCKABLE>
112inline
113void upgrading_lock<LOCKABLE>::upgrade()
114{
115 if (!m_exclusive) {
116 m_obj.unlock_upgrade_and_lock();
117 m_exclusive = true;
118 }
119}
120
121
122
123} // namespace AthContainers_detail