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