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