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