00001
00002
00015 #ifndef ATHCONTAINERS_THREADING_H
00016 #define ATHCONTAINERS_THREADING_H
00017
00018
00019 #if defined(XAOD_STANDALONE) || defined(__GCCXML__)
00020 # ifndef ATHCONTAINERS_NO_THREADS
00021 # define ATHCONTAINERS_NO_THREADS
00022 # endif
00023 #endif
00024
00025
00026 #ifdef ATHCONTAINERS_NO_THREADS
00027
00028
00029 namespace AthContainers_detail {
00030
00031
00035 class mutex {};
00036
00037
00041 template <class LOCKABLE>
00042 class lock_guard
00043 {
00044 public:
00045 lock_guard() {}
00046 lock_guard(LOCKABLE&) {}
00047 };
00048
00049
00053 class upgrade_mutex
00054 {
00055 public:
00056 void lock() {}
00057 void unlock() {}
00058 void lock_shared() {}
00059 void unlock_shared() {}
00060 void lock_upgrade() {}
00061 void unlock_upgrade() {}
00062 void unlock_upgrade_and_lock() {}
00063 private:
00064
00065
00066 upgrade_mutex& operator= (const upgrade_mutex&);
00067 };
00068
00069
00073 template <class T>
00074 class thread_specific_ptr
00075 {
00076 public:
00077 thread_specific_ptr() : m_ptr(0) {}
00078 ~thread_specific_ptr() { delete m_ptr; }
00079 T* get() const { return m_ptr; }
00080 T* operator->() const { return m_ptr; }
00081 T& operator*() const { return *m_ptr; }
00082 void reset (T* new_value=0) { delete m_ptr; m_ptr = new_value; }
00083 T* release() { T* ret = m_ptr; m_ptr = 0; return ret; }
00084
00085 private:
00086 T* m_ptr;
00087 };
00088
00089
00091 inline void fence_acq_rel() {}
00092 inline void fence_seq_cst() {}
00093
00094
00095 }
00096
00097
00098 #else // not ATHCONTAINERS_NO_THREADS
00099
00100
00101 #ifdef XAOD_ANALYSIS
00102 #ifndef BOOST_SYSTEM_NO_DEPRECATED
00103 #define BOOST_SYSTEM_NO_DEPRECATED 1
00104 #endif
00105 #endif
00106
00107 #include "boost/thread/shared_mutex.hpp"
00108 #include "boost/thread/tss.hpp"
00109 #if __cplusplus > 201100
00110 # include <atomic>
00111 # include <mutex>
00112 # include <thread>
00113 namespace SG_STD_OR_BOOST = std;
00114 #else
00115 # include "boost/atomic.hpp"
00116 # include "boost/thread/mutex.hpp"
00117 # include "boost/thread/thread.hpp"
00118 namespace SG_STD_OR_BOOST = boost;
00119 #endif
00120
00121
00122 namespace AthContainers_detail {
00123
00124
00125
00126 using boost::upgrade_mutex;
00127 using boost::thread_specific_ptr;
00128
00129
00130 using SG_STD_OR_BOOST::mutex;
00131 using SG_STD_OR_BOOST::lock_guard;
00132 using SG_STD_OR_BOOST::thread;
00133
00134
00138 void fence_acq_rel();
00139
00140
00144 void fence_seq_cst();
00145
00146
00147 }
00148
00149
00150 #endif // not ATHCONTAINERS_NO_THREADS
00151
00152
00153
00154 namespace AthContainers_detail {
00155
00156
00163 template <typename LOCKABLE>
00164 class strict_shared_lock
00165 {
00166 public:
00168 typedef LOCKABLE lockable_type;
00169
00170
00175 explicit strict_shared_lock(lockable_type& obj);
00176
00177
00182 explicit strict_shared_lock(const lockable_type& obj);
00183
00184
00188 ~strict_shared_lock();
00189
00190
00191 private:
00192
00193 strict_shared_lock();
00194 strict_shared_lock(strict_shared_lock const&);
00195 strict_shared_lock& operator=(strict_shared_lock const&);
00196
00197
00198 private:
00200 lockable_type& m_obj;
00201 };
00202
00203
00212 template <class LOCKABLE>
00213 class upgrading_lock
00214 {
00215 public:
00217 typedef LOCKABLE lockable_type;
00218
00219
00224 explicit upgrading_lock (lockable_type& obj);
00225
00226
00230 ~upgrading_lock();
00231
00232
00236 void upgrade();
00237
00238
00239 private:
00240
00241 upgrading_lock();
00242 upgrading_lock(upgrading_lock const&);
00243 upgrading_lock& operator=(upgrading_lock const&);
00244
00245
00246 private:
00248 lockable_type& m_obj;
00249
00251 bool m_exclusive;
00252 };
00253
00254
00255 }
00256
00257
00258 #include "AthContainers/tools/threading.icc"
00259
00260
00261 #endif // not ATHCONTAINERS_THREADING_H