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