11 #ifndef ASIO_DETAIL_STD_EVENT_HPP 12 #define ASIO_DETAIL_STD_EVENT_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 20 #if defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR) 23 #include <condition_variable> 48 template <
typename Lock>
49 void signal(Lock& lock)
51 this->signal_all(lock);
55 template <
typename Lock>
56 void signal_all(Lock& lock)
65 template <
typename Lock>
66 void unlock_and_signal_one(Lock& lock)
70 bool have_waiters = (state_ > 1);
77 template <
typename Lock>
78 bool maybe_unlock_and_signal_one(Lock& lock)
92 template <
typename Lock>
93 void clear(Lock& lock)
97 state_ &= ~
std::size_t(1);
101 template <
typename Lock>
102 void wait(Lock& lock)
105 unique_lock_adapter u_lock(lock);
106 while ((state_ & 1) == 0)
109 cond_.wait(u_lock.unique_lock_);
114 template <
typename Lock>
115 bool wait_for_usec(Lock& lock,
long usec)
118 unique_lock_adapter u_lock(lock);
119 if ((state_ & 1) == 0)
122 cond_.wait_for(u_lock.unique_lock_, std::chrono::microseconds(usec));
124 return (state_ & 1) != 0;
130 struct unique_lock_adapter
132 template <
typename Lock>
133 explicit unique_lock_adapter(Lock& lock)
134 : unique_lock_(lock.
mutex().mutex_,
std::adopt_lock)
138 ~unique_lock_adapter()
140 unique_lock_.release();
143 std::unique_lock<std::mutex> unique_lock_;
150 explicit waiter(std::size_t& state)
165 std::condition_variable cond_;
174 #endif // defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR) 176 #endif // ASIO_DETAIL_STD_EVENT_HPP #define ASIO_ASSERT(expr)