File indexing completed on 2025-07-15 08:36:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_SHM_NAMED_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_SHM_NAMED_CONDITION_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
0025 #include <boost/interprocess/sync/cv_status.hpp>
0026 #include <boost/static_assert.hpp>
0027 #include <boost/interprocess/detail/type_traits.hpp>
0028 #include <boost/interprocess/creation_tags.hpp>
0029 #include <boost/interprocess/exceptions.hpp>
0030 #include <boost/interprocess/shared_memory_object.hpp>
0031 #include <boost/interprocess/sync/interprocess_condition.hpp>
0032 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0033 #include <boost/interprocess/sync/shm/named_creation_functor.hpp>
0034 #include <boost/interprocess/sync/named_mutex.hpp>
0035 #include <boost/interprocess/permissions.hpp>
0036 #include <boost/interprocess/timed_utils.hpp>
0037 #if defined (BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES)
0038 #include <boost/interprocess/sync/interprocess_mutex.hpp>
0039 #include <boost/interprocess/sync/scoped_lock.hpp>
0040 #include <boost/interprocess/sync/detail/condition_any_algorithm.hpp>
0041 #else
0042 #include <boost/interprocess/sync/detail/locks.hpp>
0043 #endif
0044
0045
0046
0047
0048
0049 namespace boost {
0050 namespace interprocess {
0051 namespace ipcdetail {
0052
0053 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0054 class interprocess_tester;
0055 #endif
0056
0057
0058
0059
0060 class shm_named_condition
0061 {
0062 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0063
0064 shm_named_condition();
0065 shm_named_condition(const shm_named_condition &);
0066 shm_named_condition &operator=(const shm_named_condition &);
0067 #endif
0068 public:
0069
0070
0071 shm_named_condition(create_only_t, const char *name, const permissions &perm = permissions());
0072
0073
0074
0075
0076
0077
0078
0079 shm_named_condition(open_or_create_t, const char *name, const permissions &perm = permissions());
0080
0081
0082
0083
0084 shm_named_condition(open_only_t, const char *name);
0085
0086 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0087
0088
0089
0090
0091
0092
0093 shm_named_condition(create_only_t, const wchar_t *name, const permissions &perm = permissions());
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 shm_named_condition(open_or_create_t, const wchar_t *name, const permissions &perm = permissions());
0105
0106
0107
0108
0109
0110
0111
0112 shm_named_condition(open_only_t, const wchar_t *name);
0113
0114 #endif
0115
0116
0117
0118
0119
0120
0121
0122 ~shm_named_condition();
0123
0124
0125
0126 void notify_one();
0127
0128
0129
0130 void notify_all();
0131
0132
0133
0134
0135 template <typename L>
0136 void wait(L& lock);
0137
0138
0139
0140 template <typename L, typename Pr>
0141 void wait(L& lock, Pr pred);
0142
0143
0144
0145
0146
0147
0148 template <typename L, typename TimePoint>
0149 bool timed_wait(L& lock, const TimePoint &abs_time);
0150
0151
0152
0153
0154 template <typename L, typename TimePoint, typename Pr>
0155 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred);
0156
0157
0158
0159 template <typename L, class TimePoint>
0160 cv_status wait_until(L& lock, const TimePoint &abs_time)
0161 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0162
0163
0164
0165 template <typename L, class TimePoint, typename Pr>
0166 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0167 { return this->timed_wait(lock, abs_time, pred); }
0168
0169
0170
0171 template <typename L, class Duration>
0172 cv_status wait_for(L& lock, const Duration &dur)
0173 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0174
0175
0176
0177 template <typename L, class Duration, typename Pr>
0178 bool wait_for(L& lock, const Duration &dur, Pr pred)
0179 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0180
0181
0182
0183 static bool remove(const char *name);
0184
0185 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0186
0187
0188
0189
0190
0191
0192 static bool remove(const wchar_t *name);
0193
0194 #endif
0195
0196 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0197 private:
0198
0199 #if defined (BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES)
0200 class internal_condition_members
0201 {
0202 public:
0203 typedef interprocess_mutex mutex_type;
0204 typedef interprocess_condition condvar_type;
0205
0206 condvar_type& get_condvar() { return m_cond; }
0207 mutex_type& get_mutex() { return m_mtx; }
0208
0209 private:
0210 mutex_type m_mtx;
0211 condvar_type m_cond;
0212 };
0213
0214 typedef ipcdetail::condition_any_wrapper<internal_condition_members> internal_condition;
0215 #else
0216 typedef interprocess_condition internal_condition;
0217 #endif
0218
0219 internal_condition &internal_cond()
0220 { return *static_cast<internal_condition*>(m_shmem.get_user_address()); }
0221
0222 friend class boost::interprocess::ipcdetail::interprocess_tester;
0223 void dont_close_on_destruction();
0224
0225 typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
0226 open_create_impl_t m_shmem;
0227
0228 template <class T, class Arg> friend class boost::interprocess::ipcdetail::named_creation_functor;
0229 typedef boost::interprocess::ipcdetail::named_creation_functor<internal_condition> construct_func_t;
0230 #endif
0231 };
0232
0233 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0234
0235 inline shm_named_condition::~shm_named_condition()
0236 {}
0237
0238 inline shm_named_condition::shm_named_condition(create_only_t, const char *name, const permissions &perm)
0239 : m_shmem (create_only
0240 ,name
0241 ,sizeof(internal_condition) +
0242 open_create_impl_t::ManagedOpenOrCreateUserOffset
0243 ,read_write
0244 ,0
0245 ,construct_func_t(DoCreate)
0246 ,perm)
0247 {}
0248
0249 inline shm_named_condition::shm_named_condition(open_or_create_t, const char *name, const permissions &perm)
0250 : m_shmem (open_or_create
0251 ,name
0252 ,sizeof(internal_condition) +
0253 open_create_impl_t::ManagedOpenOrCreateUserOffset
0254 ,read_write
0255 ,0
0256 ,construct_func_t(DoOpenOrCreate)
0257 ,perm)
0258 {}
0259
0260 inline shm_named_condition::shm_named_condition(open_only_t, const char *name)
0261 : m_shmem (open_only
0262 ,name
0263 ,read_write
0264 ,0
0265 ,construct_func_t(DoOpen))
0266 {}
0267
0268 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0269
0270 inline shm_named_condition::shm_named_condition(create_only_t, const wchar_t *name, const permissions &perm)
0271 : m_shmem (create_only
0272 ,name
0273 ,sizeof(internal_condition) +
0274 open_create_impl_t::ManagedOpenOrCreateUserOffset
0275 ,read_write
0276 ,0
0277 ,construct_func_t(DoCreate)
0278 ,perm)
0279 {}
0280
0281 inline shm_named_condition::shm_named_condition(open_or_create_t, const wchar_t *name, const permissions &perm)
0282 : m_shmem (open_or_create
0283 ,name
0284 ,sizeof(internal_condition) +
0285 open_create_impl_t::ManagedOpenOrCreateUserOffset
0286 ,read_write
0287 ,0
0288 ,construct_func_t(DoOpenOrCreate)
0289 ,perm)
0290 {}
0291
0292 inline shm_named_condition::shm_named_condition(open_only_t, const wchar_t *name)
0293 : m_shmem (open_only
0294 ,name
0295 ,read_write
0296 ,0
0297 ,construct_func_t(DoOpen))
0298 {}
0299
0300 #endif
0301
0302 inline void shm_named_condition::dont_close_on_destruction()
0303 { interprocess_tester::dont_close_on_destruction(m_shmem); }
0304
0305 inline void shm_named_condition::notify_one()
0306 { this->internal_cond().notify_one(); }
0307
0308 inline void shm_named_condition::notify_all()
0309 { this->internal_cond().notify_all(); }
0310
0311 template <typename L>
0312 inline void shm_named_condition::wait(L& lock)
0313 { this->internal_cond().wait(lock); }
0314
0315 template <typename L, typename Pr>
0316 inline void shm_named_condition::wait(L& lock, Pr pred)
0317 { this->internal_cond().wait(lock, pred); }
0318
0319 template <typename L, typename TimePoint>
0320 inline bool shm_named_condition::timed_wait
0321 (L& lock, const TimePoint &abs_time)
0322 { return this->internal_cond().timed_wait(lock, abs_time); }
0323
0324 template <typename L, typename TimePoint, typename Pr>
0325 inline bool shm_named_condition::timed_wait
0326 (L& lock, const TimePoint &abs_time, Pr pred)
0327 { return this->internal_cond().timed_wait(lock, abs_time, pred); }
0328
0329 inline bool shm_named_condition::remove(const char *name)
0330 { return shared_memory_object::remove(name); }
0331
0332 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0333
0334 inline bool shm_named_condition::remove(const wchar_t *name)
0335 { return shared_memory_object::remove(name); }
0336
0337 #endif
0338
0339
0340 #endif
0341
0342 }
0343 }
0344 }
0345
0346 #include <boost/interprocess/detail/config_end.hpp>
0347
0348 #endif