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_SHARABLE_MUTEX_HPP
0012 #define BOOST_INTERPROCESS_NAMED_SHARABLE_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/shared_memory_object.hpp>
0027 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0028 #include <boost/interprocess/sync/interprocess_sharable_mutex.hpp>
0029 #include <boost/interprocess/sync/shm/named_creation_functor.hpp>
0030 #include <boost/interprocess/permissions.hpp>
0031
0032
0033
0034
0035 namespace boost {
0036 namespace interprocess {
0037
0038 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0039 namespace ipcdetail{ class interprocess_tester; }
0040 #endif
0041
0042 class named_condition;
0043
0044
0045
0046
0047 class named_sharable_mutex
0048 {
0049 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0050
0051 named_sharable_mutex();
0052 named_sharable_mutex(const named_sharable_mutex &);
0053 named_sharable_mutex &operator=(const named_sharable_mutex &);
0054 #endif
0055 public:
0056
0057
0058
0059 named_sharable_mutex(create_only_t, const char *name, const permissions &perm = permissions());
0060
0061
0062
0063
0064
0065
0066 named_sharable_mutex(open_or_create_t, const char *name, const permissions &perm = permissions());
0067
0068
0069
0070
0071
0072 named_sharable_mutex(open_only_t, const char *name);
0073
0074 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0075
0076
0077
0078
0079
0080
0081 named_sharable_mutex(create_only_t, const wchar_t *name, const permissions &perm = permissions());
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 named_sharable_mutex(open_or_create_t, const wchar_t *name, const permissions &perm = permissions());
0092
0093
0094
0095
0096
0097
0098
0099
0100 named_sharable_mutex(open_only_t, const wchar_t *name);
0101
0102 #endif
0103
0104
0105
0106
0107
0108
0109
0110 ~named_sharable_mutex();
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 void lock();
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 bool try_lock();
0139
0140
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
0167 void unlock();
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 void lock_sharable();
0182
0183
0184
0185 void lock_shared()
0186 { this->lock_sharable(); }
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200 bool try_lock_sharable();
0201
0202
0203
0204 bool try_lock_shared()
0205 { return this->try_lock_sharable(); }
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218 template<class TimePoint>
0219 bool timed_lock_sharable(const TimePoint &abs_time);
0220
0221
0222
0223 template<class TimePoint> bool try_lock_shared_until(const TimePoint &abs_time)
0224 { return this->timed_lock_sharable(abs_time); }
0225
0226
0227
0228 template<class Duration> bool try_lock_shared_for(const Duration &dur)
0229 { return this->timed_lock_sharable(ipcdetail::duration_to_ustime(dur)); }
0230
0231
0232
0233
0234 void unlock_sharable();
0235
0236
0237
0238 void unlock_shared()
0239 { this->unlock_sharable(); }
0240
0241
0242
0243 static bool remove(const char *name);
0244
0245 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0246
0247
0248
0249 static bool remove(const wchar_t *name);
0250
0251 #endif
0252
0253 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0254 private:
0255 friend class ipcdetail::interprocess_tester;
0256 void dont_close_on_destruction();
0257
0258 interprocess_sharable_mutex *mutex() const
0259 { return static_cast<interprocess_sharable_mutex*>(m_shmem.get_user_address()); }
0260
0261 typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
0262 open_create_impl_t m_shmem;
0263 typedef ipcdetail::named_creation_functor<interprocess_sharable_mutex> construct_func_t;
0264 #endif
0265 };
0266
0267 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0268
0269 inline named_sharable_mutex::~named_sharable_mutex()
0270 {}
0271
0272 inline named_sharable_mutex::named_sharable_mutex
0273 (create_only_t, const char *name, const permissions &perm)
0274 : m_shmem (create_only
0275 ,name
0276 ,sizeof(interprocess_sharable_mutex) +
0277 open_create_impl_t::ManagedOpenOrCreateUserOffset
0278 ,read_write
0279 ,0
0280 ,construct_func_t(ipcdetail::DoCreate)
0281 ,perm)
0282 {}
0283
0284 inline named_sharable_mutex::named_sharable_mutex
0285 (open_or_create_t, const char *name, const permissions &perm)
0286 : m_shmem (open_or_create
0287 ,name
0288 ,sizeof(interprocess_sharable_mutex) +
0289 open_create_impl_t::ManagedOpenOrCreateUserOffset
0290 ,read_write
0291 ,0
0292 ,construct_func_t(ipcdetail::DoOpenOrCreate)
0293 ,perm)
0294 {}
0295
0296 inline named_sharable_mutex::named_sharable_mutex
0297 (open_only_t, const char *name)
0298 : m_shmem (open_only
0299 ,name
0300 ,read_write
0301 ,0
0302 ,construct_func_t(ipcdetail::DoOpen))
0303 {}
0304
0305 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0306
0307 inline named_sharable_mutex::named_sharable_mutex
0308 (create_only_t, const wchar_t *name, const permissions &perm)
0309 : m_shmem (create_only
0310 ,name
0311 ,sizeof(interprocess_sharable_mutex) +
0312 open_create_impl_t::ManagedOpenOrCreateUserOffset
0313 ,read_write
0314 ,0
0315 ,construct_func_t(ipcdetail::DoCreate)
0316 ,perm)
0317 {}
0318
0319 inline named_sharable_mutex::named_sharable_mutex
0320 (open_or_create_t, const wchar_t *name, const permissions &perm)
0321 : m_shmem (open_or_create
0322 ,name
0323 ,sizeof(interprocess_sharable_mutex) +
0324 open_create_impl_t::ManagedOpenOrCreateUserOffset
0325 ,read_write
0326 ,0
0327 ,construct_func_t(ipcdetail::DoOpenOrCreate)
0328 ,perm)
0329 {}
0330
0331 inline named_sharable_mutex::named_sharable_mutex
0332 (open_only_t, const wchar_t *name)
0333 : m_shmem (open_only
0334 ,name
0335 ,read_write
0336 ,0
0337 ,construct_func_t(ipcdetail::DoOpen))
0338 {}
0339
0340 #endif
0341
0342 inline void named_sharable_mutex::dont_close_on_destruction()
0343 { ipcdetail::interprocess_tester::dont_close_on_destruction(m_shmem); }
0344
0345 inline void named_sharable_mutex::lock()
0346 { this->mutex()->lock(); }
0347
0348 inline void named_sharable_mutex::unlock()
0349 { this->mutex()->unlock(); }
0350
0351 inline bool named_sharable_mutex::try_lock()
0352 { return this->mutex()->try_lock(); }
0353
0354 template<class TimePoint>
0355 inline bool named_sharable_mutex::timed_lock
0356 (const TimePoint &abs_time)
0357 { return this->mutex()->timed_lock(abs_time); }
0358
0359 inline void named_sharable_mutex::lock_sharable()
0360 { this->mutex()->lock_sharable(); }
0361
0362 inline void named_sharable_mutex::unlock_sharable()
0363 { this->mutex()->unlock_sharable(); }
0364
0365 inline bool named_sharable_mutex::try_lock_sharable()
0366 { return this->mutex()->try_lock_sharable(); }
0367
0368 template<class TimePoint>
0369 inline bool named_sharable_mutex::timed_lock_sharable
0370 (const TimePoint &abs_time)
0371 { return this->mutex()->timed_lock_sharable(abs_time); }
0372
0373 inline bool named_sharable_mutex::remove(const char *name)
0374 { return shared_memory_object::remove(name); }
0375
0376 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0377
0378 inline bool named_sharable_mutex::remove(const wchar_t *name)
0379 { return shared_memory_object::remove(name); }
0380
0381 #endif
0382
0383 #endif
0384
0385 }
0386 }
0387
0388 #include <boost/interprocess/detail/config_end.hpp>
0389
0390 #endif