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