File indexing completed on 2025-01-18 09:38:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_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/sync/interprocess_mutex.hpp>
0027 #include <boost/interprocess/sync/scoped_lock.hpp>
0028 #include <boost/interprocess/exceptions.hpp>
0029 #include <boost/interprocess/sync/windows/semaphore.hpp>
0030 #include <boost/interprocess/sync/windows/mutex.hpp>
0031 #include <boost/interprocess/sync/detail/condition_algorithm_8a.hpp>
0032
0033
0034 namespace boost {
0035 namespace interprocess {
0036 namespace ipcdetail {
0037
0038 class winapi_condition
0039 {
0040 winapi_condition(const winapi_condition &);
0041 winapi_condition &operator=(const winapi_condition &);
0042
0043 public:
0044 winapi_condition()
0045 : m_condition_data()
0046 {}
0047
0048 ~winapi_condition()
0049 {
0050
0051
0052 this->notify_all();
0053 }
0054
0055 void notify_one()
0056 { m_condition_data.notify_one(); }
0057
0058 void notify_all()
0059 { m_condition_data.notify_all(); }
0060
0061 template <typename L>
0062 void wait(L& lock)
0063 { m_condition_data.wait(lock); }
0064
0065 template <typename L, typename Pr>
0066 void wait(L& lock, Pr pred)
0067 { m_condition_data.wait(lock, pred); }
0068
0069
0070 template <typename L, typename TimePoint>
0071 bool timed_wait(L& lock, const TimePoint &abs_time)
0072 { return m_condition_data.timed_wait(lock, abs_time); }
0073
0074 template <typename L, typename TimePoint, typename Pr>
0075 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0076 { return m_condition_data.timed_wait(lock, abs_time, pred); }
0077
0078 template <typename L, class TimePoint>
0079 cv_status wait_until(L& lock, const TimePoint &abs_time)
0080 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0081
0082 template <typename L, class TimePoint, typename Pr>
0083 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0084 { return this->timed_wait(lock, abs_time, pred); }
0085
0086 template <typename L, class Duration>
0087 cv_status wait_for(L& lock, const Duration &dur)
0088 { return this->wait_until(lock, duration_to_ustime(dur)); }
0089
0090 template <typename L, class Duration, typename Pr>
0091 bool wait_for(L& lock, const Duration &dur, Pr pred)
0092 { return this->wait_until(lock, duration_to_ustime(dur), pred); }
0093
0094 private:
0095
0096 struct condition_data
0097 {
0098 typedef unsigned int integer_type;
0099 typedef winapi_semaphore semaphore_type;
0100 typedef winapi_mutex mutex_type;
0101
0102 condition_data()
0103 : m_nwaiters_blocked(0)
0104 , m_nwaiters_gone(0)
0105 , m_nwaiters_to_unblock(0)
0106 , m_sem_block_queue(0)
0107 , m_sem_block_lock(1)
0108 , m_mtx_unblock_lock()
0109 {}
0110
0111 integer_type &get_nwaiters_blocked()
0112 { return m_nwaiters_blocked; }
0113
0114 integer_type &get_nwaiters_gone()
0115 { return m_nwaiters_gone; }
0116
0117 integer_type &get_nwaiters_to_unblock()
0118 { return m_nwaiters_to_unblock; }
0119
0120 semaphore_type &get_sem_block_queue()
0121 { return m_sem_block_queue; }
0122
0123 semaphore_type &get_sem_block_lock()
0124 { return m_sem_block_lock; }
0125
0126 mutex_type &get_mtx_unblock_lock()
0127 { return m_mtx_unblock_lock; }
0128
0129 integer_type m_nwaiters_blocked;
0130 integer_type m_nwaiters_gone;
0131 integer_type m_nwaiters_to_unblock;
0132 semaphore_type m_sem_block_queue;
0133 semaphore_type m_sem_block_lock;
0134 mutex_type m_mtx_unblock_lock;
0135 };
0136
0137 ipcdetail::condition_8a_wrapper<condition_data> m_condition_data;
0138 };
0139
0140 }
0141 }
0142 }
0143
0144 #include <boost/interprocess/detail/config_end.hpp>
0145
0146 #endif