File indexing completed on 2025-01-18 09:38:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_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 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0023
0024 #include <boost/interprocess/detail/config_begin.hpp>
0025 #include <boost/interprocess/detail/workaround.hpp>
0026
0027 #include <boost/interprocess/sync/cv_status.hpp>
0028 #include <boost/interprocess/sync/interprocess_mutex.hpp>
0029 #include <boost/interprocess/sync/detail/locks.hpp>
0030 #include <boost/interprocess/exceptions.hpp>
0031 #include <boost/limits.hpp>
0032 #include <boost/assert.hpp>
0033
0034 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined(BOOST_INTERPROCESS_POSIX_PROCESS_SHARED)
0035 #include <boost/interprocess/sync/posix/condition.hpp>
0036 #define BOOST_INTERPROCESS_CONDITION_USE_POSIX
0037
0038 #elif !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0039 #include <boost/interprocess/sync/windows/condition.hpp>
0040 #define BOOST_INTERPROCESS_CONDITION_USE_WINAPI
0041 #else
0042
0043 #include <boost/interprocess/sync/spin/condition.hpp>
0044 #endif
0045
0046 #endif
0047
0048
0049
0050
0051 namespace boost {
0052 namespace interprocess {
0053
0054 class named_condition;
0055
0056
0057
0058
0059
0060
0061
0062
0063 class interprocess_condition
0064 {
0065 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0066
0067 interprocess_condition(const interprocess_condition &);
0068 interprocess_condition &operator=(const interprocess_condition &);
0069 friend class named_condition;
0070 #endif
0071
0072 public:
0073
0074 interprocess_condition()
0075 {}
0076
0077
0078
0079 ~interprocess_condition()
0080 {}
0081
0082
0083
0084 void notify_one()
0085 { m_condition.notify_one(); }
0086
0087
0088
0089 void notify_all()
0090 { m_condition.notify_all(); }
0091
0092
0093
0094
0095 template <typename L>
0096 void wait(L& lock)
0097 {
0098 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0099 m_condition.wait(internal_lock);
0100 }
0101
0102
0103
0104 template <typename L, typename Pr>
0105 void wait(L& lock, Pr pred)
0106 {
0107 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0108 m_condition.wait(internal_lock, pred);
0109 }
0110
0111
0112
0113
0114
0115
0116 template <typename L, class TimePoint>
0117 bool timed_wait(L& lock, const TimePoint &abs_time)
0118 {
0119 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0120 return m_condition.timed_wait(internal_lock, abs_time);
0121 }
0122
0123
0124
0125
0126 template <typename L, class TimePoint, typename Pr>
0127 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0128 {
0129 ipcdetail::internal_mutex_lock<L> internal_lock(lock);
0130 return m_condition.timed_wait(internal_lock, abs_time, pred);
0131 }
0132
0133
0134
0135 template <typename L, class TimePoint>
0136 cv_status wait_until(L& lock, const TimePoint &abs_time)
0137 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0138
0139
0140
0141 template <typename L, class TimePoint, typename Pr>
0142 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0143 { return this->timed_wait(lock, abs_time, pred); }
0144
0145
0146
0147 template <typename L, class Duration>
0148 cv_status wait_for(L& lock, const Duration &dur)
0149 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0150
0151
0152
0153 template <typename L, class Duration, typename Pr>
0154 bool wait_for(L& lock, const Duration &dur, Pr pred)
0155 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0156
0157 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0158
0159 private:
0160 #if defined(BOOST_INTERPROCESS_CONDITION_USE_POSIX)
0161 ipcdetail::posix_condition m_condition;
0162 #elif defined(BOOST_INTERPROCESS_CONDITION_USE_WINAPI)
0163 ipcdetail::winapi_condition m_condition;
0164 #else
0165 ipcdetail::spin_condition m_condition;
0166 #endif
0167
0168 #endif
0169 };
0170
0171 }
0172 }
0173
0174 #include <boost/interprocess/detail/config_end.hpp>
0175
0176 #endif