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