File indexing completed on 2025-07-03 08:17:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_NAMED_CONDITION_ANY_HPP
0012 #define BOOST_INTERPROCESS_NAMED_CONDITION_ANY_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_any.hpp>
0034 #define BOOST_INTERPROCESS_NAMED_CONDITION_ANY_USE_WINAPI
0035 #else
0036 #include <boost/interprocess/sync/shm/named_condition_any.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_any
0053 {
0054 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0055
0056 named_condition_any();
0057 named_condition_any(const named_condition_any &);
0058 named_condition_any &operator=(const named_condition_any &);
0059 #endif
0060
0061 public:
0062
0063
0064 named_condition_any(create_only_t, const char *name, const permissions &perm = permissions())
0065 : m_cond(create_only_t(), name, perm)
0066 {}
0067
0068
0069
0070
0071
0072
0073
0074 named_condition_any(open_or_create_t, const char *name, const permissions &perm = permissions())
0075 : m_cond(open_or_create_t(), name, perm)
0076 {}
0077
0078
0079
0080
0081 named_condition_any(open_only_t, const char *name)
0082 : m_cond(open_only_t(), name)
0083 {}
0084
0085 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0086
0087
0088
0089
0090
0091
0092 named_condition_any(create_only_t, const wchar_t *name, const permissions &perm = permissions())
0093 : m_cond(create_only_t(), name, perm)
0094 {}
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 named_condition_any(open_or_create_t, const wchar_t *name, const permissions &perm = permissions())
0106 : m_cond(open_or_create_t(), name, perm)
0107 {}
0108
0109
0110
0111
0112
0113
0114
0115 named_condition_any(open_only_t, const wchar_t *name)
0116 : m_cond(open_only_t(), name)
0117 {}
0118
0119 #endif
0120
0121
0122
0123
0124
0125
0126
0127 ~named_condition_any()
0128 {}
0129
0130
0131
0132 void notify_one()
0133 { m_cond.notify_one(); }
0134
0135
0136
0137 void notify_all()
0138 { m_cond.notify_all(); }
0139
0140
0141
0142
0143 template <typename L>
0144 void wait(L& lock)
0145 { return m_cond.wait(lock); }
0146
0147
0148
0149 template <typename L, typename Pr>
0150 void wait(L& lock, Pr pred)
0151 { return m_cond.wait(lock, pred); }
0152
0153
0154
0155
0156
0157
0158 template <typename L, typename TimePoint>
0159 bool timed_wait(L& lock, const TimePoint &abs_time)
0160 { return m_cond.timed_wait(lock, abs_time); }
0161
0162
0163
0164
0165 template <typename L, typename TimePoint, typename Pr>
0166 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0167 { return m_cond.timed_wait(lock, abs_time, pred); }
0168
0169
0170
0171 template <typename L, class TimePoint>
0172 cv_status wait_until(L& lock, const TimePoint &abs_time)
0173 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0174
0175
0176
0177 template <typename L, class TimePoint, typename Pr>
0178 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0179 { return this->timed_wait(lock, abs_time, pred); }
0180
0181
0182
0183 template <typename L, class Duration>
0184 cv_status wait_for(L& lock, const Duration &dur)
0185 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0186
0187
0188
0189 template <typename L, class Duration, typename Pr>
0190 bool wait_for(L& lock, const Duration &dur, Pr pred)
0191 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0192
0193
0194
0195 static bool remove(const char *name)
0196 { return condition_any_type::remove(name); }
0197
0198 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0199
0200
0201
0202
0203
0204
0205 static bool remove(const wchar_t *name)
0206 { return condition_any_type::remove(name); }
0207
0208 #endif
0209
0210 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0211 private:
0212 #if defined(BOOST_INTERPROCESS_NAMED_CONDITION_ANY_USE_WINAPI)
0213 typedef ipcdetail::winapi_named_condition_any condition_any_type;
0214 #else
0215 typedef ipcdetail::shm_named_condition_any condition_any_type;
0216 #endif
0217 condition_any_type m_cond;
0218
0219 friend class ipcdetail::interprocess_tester;
0220 void dont_close_on_destruction()
0221 { ipcdetail::interprocess_tester::dont_close_on_destruction(m_cond); }
0222 #endif
0223 };
0224
0225 }
0226 }
0227
0228 #include <boost/interprocess/detail/config_end.hpp>
0229
0230 #endif