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