File indexing completed on 2025-07-01 08:18:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_NAMED_MUTEX_HPP
0012 #define BOOST_INTERPROCESS_NAMED_MUTEX_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024 #include <boost/interprocess/creation_tags.hpp>
0025 #include <boost/interprocess/exceptions.hpp>
0026 #include <boost/interprocess/timed_utils.hpp>
0027 #include <boost/interprocess/detail/interprocess_tester.hpp>
0028 #include <boost/interprocess/permissions.hpp>
0029
0030 #if defined(BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES)
0031 #include <boost/interprocess/sync/posix/named_mutex.hpp>
0032 #define BOOST_INTERPROCESS_NAMED_MUTEX_USE_POSIX
0033 #elif !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0034 #include <boost/interprocess/sync/windows/named_mutex.hpp>
0035 #define BOOST_INTERPROCESS_NAMED_MUTEX_USE_WINAPI
0036 #else
0037 #include <boost/interprocess/sync/shm/named_mutex.hpp>
0038 #endif
0039
0040
0041
0042
0043 namespace boost {
0044 namespace interprocess {
0045
0046 class named_condition;
0047
0048
0049
0050
0051 class named_mutex
0052 {
0053 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0054
0055
0056 named_mutex();
0057 named_mutex(const named_mutex &);
0058 named_mutex &operator=(const named_mutex &);
0059 friend class named_condition;
0060 #endif
0061
0062 public:
0063
0064
0065 named_mutex(create_only_t, const char *name, const permissions &perm = permissions());
0066
0067
0068
0069
0070
0071
0072
0073 named_mutex(open_or_create_t, const char *name, const permissions &perm = permissions());
0074
0075
0076
0077
0078 named_mutex(open_only_t, const char *name);
0079
0080 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0081
0082
0083
0084
0085
0086
0087 named_mutex(create_only_t, const wchar_t *name, const permissions &perm = permissions());
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 named_mutex(open_or_create_t, const wchar_t *name, const permissions &perm = permissions());
0099
0100
0101
0102
0103
0104
0105
0106 named_mutex(open_only_t, const wchar_t *name);
0107
0108 #endif
0109
0110
0111
0112
0113
0114
0115
0116 ~named_mutex();
0117
0118
0119
0120 void unlock();
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 void lock();
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 bool try_lock();
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 template<class TimePoint>
0153 bool timed_lock(const TimePoint &abs_time);
0154
0155
0156
0157 template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0158 { return this->timed_lock(abs_time); }
0159
0160
0161
0162 template<class Duration> bool try_lock_for(const Duration &dur)
0163 { return this->timed_lock(ipcdetail::duration_to_ustime(dur)); }
0164
0165
0166
0167 static bool remove(const char *name);
0168
0169 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0170
0171
0172
0173
0174
0175
0176 static bool remove(const wchar_t *name);
0177
0178 #endif
0179
0180 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0181 private:
0182 friend class ipcdetail::interprocess_tester;
0183 void dont_close_on_destruction();
0184
0185 public:
0186 #if defined(BOOST_INTERPROCESS_NAMED_MUTEX_USE_POSIX)
0187 typedef ipcdetail::posix_named_mutex internal_mutex_type;
0188 #elif defined(BOOST_INTERPROCESS_NAMED_MUTEX_USE_WINAPI)
0189 typedef ipcdetail::winapi_named_mutex internal_mutex_type;
0190 #else
0191 typedef ipcdetail::shm_named_mutex internal_mutex_type;
0192 #endif
0193 internal_mutex_type &internal_mutex()
0194 { return m_mut; }
0195
0196 internal_mutex_type m_mut;
0197
0198 #endif
0199 };
0200
0201 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0202
0203 inline named_mutex::named_mutex(create_only_t, const char *name, const permissions &perm)
0204 : m_mut(create_only_t(), name, perm)
0205 {}
0206
0207 inline named_mutex::named_mutex(open_or_create_t, const char *name, const permissions &perm)
0208 : m_mut(open_or_create_t(), name, perm)
0209 {}
0210
0211 inline named_mutex::named_mutex(open_only_t, const char *name)
0212 : m_mut(open_only_t(), name)
0213 {}
0214
0215 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0216
0217 inline named_mutex::named_mutex(create_only_t, const wchar_t *name, const permissions &perm)
0218 : m_mut(create_only_t(), name, perm)
0219 {}
0220
0221 inline named_mutex::named_mutex(open_or_create_t, const wchar_t *name, const permissions &perm)
0222 : m_mut(open_or_create_t(), name, perm)
0223 {}
0224
0225 inline named_mutex::named_mutex(open_only_t, const wchar_t *name)
0226 : m_mut(open_only_t(), name)
0227 {}
0228
0229 #endif
0230
0231 inline void named_mutex::dont_close_on_destruction()
0232 { ipcdetail::interprocess_tester::dont_close_on_destruction(m_mut); }
0233
0234 inline named_mutex::~named_mutex()
0235 {}
0236
0237 inline void named_mutex::lock()
0238 { m_mut.lock(); }
0239
0240 inline void named_mutex::unlock()
0241 { m_mut.unlock(); }
0242
0243 inline bool named_mutex::try_lock()
0244 { return m_mut.try_lock(); }
0245
0246 template<class TimePoint>
0247 inline bool named_mutex::timed_lock(const TimePoint &abs_time)
0248 { return m_mut.timed_lock(abs_time); }
0249
0250 inline bool named_mutex::remove(const char *name)
0251 { return internal_mutex_type::remove(name); }
0252
0253 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0254
0255 inline bool named_mutex::remove(const wchar_t *name)
0256 { return internal_mutex_type::remove(name); }
0257
0258 #endif
0259
0260 #endif
0261
0262 }
0263 }
0264
0265 #include <boost/interprocess/detail/config_end.hpp>
0266
0267 #endif