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