File indexing completed on 2026-09-18 08:52:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_NAMED_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_NAMED_CONDITION_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
0026 #include <boost/interprocess/sync/cv_status.hpp>
0027 #include <boost/interprocess/creation_tags.hpp>
0028 #include <boost/interprocess/exceptions.hpp>
0029 #include <boost/interprocess/timed_utils.hpp>
0030 #include <boost/interprocess/detail/interprocess_tester.hpp>
0031 #include <boost/interprocess/permissions.hpp>
0032 #include <boost/interprocess/sync/detail/locks.hpp>
0033 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0034 #include <boost/interprocess/sync/windows/named_condition.hpp>
0035 #define BOOST_INTERPROCESS_NAMED_CONDITION_USE_WINAPI
0036 #else
0037 #include <boost/interprocess/sync/shm/named_condition.hpp>
0038 #endif
0039
0040
0041
0042
0043 namespace boost {
0044 namespace interprocess {
0045
0046 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0047 namespace ipcdetail{ class interprocess_tester; }
0048 #endif
0049
0050
0051
0052
0053 class named_condition
0054 {
0055 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0056
0057 named_condition();
0058 named_condition(const named_condition &);
0059 named_condition &operator=(const named_condition &);
0060 #endif
0061 public:
0062
0063
0064
0065 named_condition(create_only_t, const char *name, const permissions &perm = permissions());
0066
0067
0068
0069
0070
0071
0072
0073 named_condition(open_or_create_t, const char *name, const permissions &perm = permissions());
0074
0075
0076
0077
0078 named_condition(open_only_t, const char *name);
0079
0080
0081
0082
0083
0084 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0085
0086
0087
0088
0089
0090 named_condition(create_only_t, const wchar_t *name, const permissions &perm = permissions());
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 named_condition(open_or_create_t, const wchar_t *name, const permissions &perm = permissions());
0102
0103
0104
0105
0106
0107
0108
0109 named_condition(open_only_t, const wchar_t *name);
0110
0111 #endif
0112
0113
0114
0115
0116
0117
0118
0119 ~named_condition();
0120
0121
0122
0123 void notify_one();
0124
0125
0126
0127 void notify_all();
0128
0129
0130
0131
0132 template <typename L>
0133 void wait(L& lock);
0134
0135
0136
0137 template <typename L, typename Pr>
0138 void wait(L& lock, Pr pred);
0139
0140
0141
0142
0143
0144
0145 template <typename L, class TimePoint>
0146 bool timed_wait(L& lock, const TimePoint &abs_time);
0147
0148
0149
0150
0151 template <typename L, class TimePoint, typename Pr>
0152 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred);
0153
0154
0155
0156 template <typename L, class TimePoint>
0157 cv_status wait_until(L& lock, const TimePoint &abs_time)
0158 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0159
0160
0161
0162 template <typename L, class TimePoint, typename Pr>
0163 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0164 { return this->timed_wait(lock, abs_time, pred); }
0165
0166
0167
0168 template <typename L, class Duration>
0169 cv_status wait_for(L& lock, const Duration &dur)
0170 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0171
0172
0173
0174 template <typename L, class Duration, typename Pr>
0175 bool wait_for(L& lock, const Duration &dur, Pr pred)
0176 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0177
0178
0179
0180 static bool remove(const char *name);
0181
0182 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0183
0184
0185
0186
0187
0188
0189 static bool remove(const wchar_t *name);
0190
0191 #endif
0192
0193 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0194 private:
0195 #if defined(BOOST_INTERPROCESS_NAMED_CONDITION_USE_WINAPI)
0196 typedef ipcdetail::winapi_named_condition condition_type;
0197 #else
0198 typedef ipcdetail::shm_named_condition condition_type;
0199 #endif
0200 condition_type m_cond;
0201
0202 friend class ipcdetail::interprocess_tester;
0203 void dont_close_on_destruction()
0204 { ipcdetail::interprocess_tester::dont_close_on_destruction(m_cond); }
0205 #endif
0206 };
0207
0208 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0209
0210 inline named_condition::~named_condition()
0211 {}
0212
0213 inline named_condition::named_condition(create_only_t, const char *name, const permissions &perm)
0214 : m_cond(create_only_t(), name, perm)
0215 {}
0216
0217 inline named_condition::named_condition(open_or_create_t, const char *name, const permissions &perm)
0218 : m_cond(open_or_create_t(), name, perm)
0219 {}
0220
0221 inline named_condition::named_condition(open_only_t, const char *name)
0222 : m_cond(open_only_t(), name)
0223 {}
0224
0225 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0226
0227 inline named_condition::named_condition(create_only_t, const wchar_t *name, const permissions &perm)
0228 : m_cond(create_only_t(), name, perm)
0229 {}
0230
0231 inline named_condition::named_condition(open_or_create_t, const wchar_t *name, const permissions &perm)
0232 : m_cond(open_or_create_t(), name, perm)
0233 {}
0234
0235 inline named_condition::named_condition(open_only_t, const wchar_t *name)
0236 : m_cond(open_only_t(), name)
0237 {}
0238
0239 #endif
0240
0241
0242 inline void named_condition::notify_one()
0243 { m_cond.notify_one(); }
0244
0245 inline void named_condition::notify_all()
0246 { m_cond.notify_all(); }
0247
0248 template <typename L>
0249 inline void named_condition::wait(L& lock)
0250 {
0251 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0252 m_cond.wait(internal_lock);
0253 }
0254
0255 template <typename L, typename Pr>
0256 inline void named_condition::wait(L& lock, Pr pred)
0257 {
0258 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0259 m_cond.wait(internal_lock, pred);
0260 }
0261
0262 template <typename L, typename TimePoint>
0263 inline bool named_condition::timed_wait
0264 (L& lock, const TimePoint &abs_time)
0265 {
0266 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0267 return m_cond.timed_wait(internal_lock, abs_time);
0268 }
0269
0270 template <typename L, typename TimePoint, typename Pr>
0271 inline bool named_condition::timed_wait
0272 (L& lock, const TimePoint &abs_time, Pr pred)
0273 {
0274 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0275 return m_cond.timed_wait(internal_lock, abs_time, pred);
0276 }
0277
0278 inline bool named_condition::remove(const char *name)
0279 {
0280 return condition_type::remove(name);
0281 }
0282
0283 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0284
0285 inline bool named_condition::remove(const wchar_t *name)
0286 {
0287 return condition_type::remove(name);
0288 }
0289
0290 #endif
0291
0292
0293 #endif
0294
0295 }
0296 }
0297
0298 #include <boost/interprocess/detail/config_end.hpp>
0299
0300 #endif