File indexing completed on 2025-07-05 08:35:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_INTERPROCESS_MUTEX_HPP
0016 #define BOOST_INTERPROCESS_MUTEX_HPP
0017
0018 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0019
0020 #ifndef BOOST_CONFIG_HPP
0021 # include <boost/config.hpp>
0022 #endif
0023 #
0024 #if defined(BOOST_HAS_PRAGMA_ONCE)
0025 # pragma once
0026 #endif
0027
0028 #include <boost/interprocess/detail/config_begin.hpp>
0029 #include <boost/interprocess/exceptions.hpp>
0030 #include <boost/interprocess/detail/workaround.hpp>
0031 #include <boost/interprocess/timed_utils.hpp>
0032 #include <boost/assert.hpp>
0033 #include <boost/interprocess/sync/detail/common_algorithms.hpp>
0034
0035 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_POSIX_PROCESS_SHARED)
0036 #include <boost/interprocess/sync/posix/mutex.hpp>
0037 #define BOOST_INTERPROCESS_MUTEX_USE_POSIX
0038 #elif !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0039
0040 #define BOOST_INTERPROCESS_MUTEX_USE_WINAPI
0041 #include <boost/interprocess/sync/windows/mutex.hpp>
0042 #else
0043
0044 #include <boost/interprocess/sync/spin/mutex.hpp>
0045 namespace boost {
0046 namespace interprocess {
0047 namespace ipcdetail{
0048 namespace robust_emulation_helpers {
0049
0050 template<class T>
0051 class mutex_traits;
0052
0053 }}}}
0054 #endif
0055
0056 #endif
0057
0058
0059
0060
0061
0062 namespace boost {
0063 namespace interprocess {
0064
0065 class interprocess_condition;
0066
0067
0068
0069 class interprocess_mutex
0070 {
0071 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0072
0073 interprocess_mutex(const interprocess_mutex &);
0074 interprocess_mutex &operator=(const interprocess_mutex &);
0075 friend class interprocess_condition;
0076
0077 public:
0078 #if defined(BOOST_INTERPROCESS_MUTEX_USE_POSIX)
0079 typedef ipcdetail::posix_mutex internal_mutex_type;
0080 #elif defined(BOOST_INTERPROCESS_MUTEX_USE_WINAPI)
0081 typedef ipcdetail::winapi_mutex internal_mutex_type;
0082 #else
0083 typedef ipcdetail::spin_mutex internal_mutex_type;
0084 private:
0085 friend class ipcdetail::robust_emulation_helpers::mutex_traits<interprocess_mutex>;
0086 void take_ownership(){ m_mutex.take_ownership(); }
0087 public:
0088 #endif
0089
0090 #endif
0091 public:
0092
0093
0094
0095 interprocess_mutex();
0096
0097
0098
0099 ~interprocess_mutex();
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 void lock();
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 bool try_lock();
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 template<class TimePoint>
0141 bool timed_lock(const TimePoint &abs_time);
0142
0143
0144
0145 template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0146 { return this->timed_lock(abs_time); }
0147
0148
0149
0150 template<class Duration> bool try_lock_for(const Duration &dur)
0151 { return this->timed_lock(ipcdetail::duration_to_ustime(dur)); }
0152
0153
0154
0155 void unlock();
0156
0157 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0158 internal_mutex_type &internal_mutex()
0159 { return m_mutex; }
0160
0161 const internal_mutex_type &internal_mutex() const
0162 { return m_mutex; }
0163
0164 private:
0165 internal_mutex_type m_mutex;
0166 #endif
0167 };
0168
0169 }
0170 }
0171
0172
0173 namespace boost {
0174 namespace interprocess {
0175
0176 inline interprocess_mutex::interprocess_mutex(){}
0177
0178 inline interprocess_mutex::~interprocess_mutex(){}
0179
0180 inline void interprocess_mutex::lock()
0181 { ipcdetail::timeout_when_locking_aware_lock(m_mutex); }
0182
0183 inline bool interprocess_mutex::try_lock()
0184 { return m_mutex.try_lock(); }
0185
0186 template <class TimePoint>
0187 inline bool interprocess_mutex::timed_lock(const TimePoint &abs_time)
0188 { return m_mutex.timed_lock(abs_time); }
0189
0190 inline void interprocess_mutex::unlock()
0191 { m_mutex.unlock(); }
0192
0193 }
0194 }
0195
0196 #include <boost/interprocess/detail/config_end.hpp>
0197
0198 #endif