2 // detail/win_event.hpp
3 // ~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_WIN_EVENT_HPP
12 #define BOOST_ASIO_DETAIL_WIN_EVENT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_WINDOWS)
22 #include <boost/asio/detail/assert.hpp>
23 #include <boost/asio/detail/noncopyable.hpp>
24 #include <boost/asio/detail/socket_types.hpp>
26 #include <boost/asio/detail/push_options.hpp>
37 BOOST_ASIO_DECL win_event();
40 BOOST_ASIO_DECL ~win_event();
42 // Signal the event. (Retained for backward compatibility.)
43 template <typename Lock>
44 void signal(Lock& lock)
46 this->signal_all(lock);
49 // Signal all waiters.
50 template <typename Lock>
51 void signal_all(Lock& lock)
53 BOOST_ASIO_ASSERT(lock.locked());
56 ::SetEvent(events_[0]);
59 // Unlock the mutex and signal one waiter.
60 template <typename Lock>
61 void unlock_and_signal_one(Lock& lock)
63 BOOST_ASIO_ASSERT(lock.locked());
65 bool have_waiters = (state_ > 1);
68 ::SetEvent(events_[1]);
71 // If there's a waiter, unlock the mutex and signal it.
72 template <typename Lock>
73 bool maybe_unlock_and_signal_one(Lock& lock)
75 BOOST_ASIO_ASSERT(lock.locked());
80 ::SetEvent(events_[1]);
87 template <typename Lock>
88 void clear(Lock& lock)
90 BOOST_ASIO_ASSERT(lock.locked());
92 ::ResetEvent(events_[0]);
93 state_ &= ~std::size_t(1);
96 // Wait for the event to become signalled.
97 template <typename Lock>
100 BOOST_ASIO_ASSERT(lock.locked());
101 while ((state_ & 1) == 0)
105 #if defined(BOOST_ASIO_WINDOWS_APP)
106 ::WaitForMultipleObjectsEx(2, events_, false, INFINITE, false);
107 #else // defined(BOOST_ASIO_WINDOWS_APP)
108 ::WaitForMultipleObjects(2, events_, false, INFINITE);
109 #endif // defined(BOOST_ASIO_WINDOWS_APP)
120 } // namespace detail
124 #include <boost/asio/detail/pop_options.hpp>
126 #if defined(BOOST_ASIO_HEADER_ONLY)
127 # include <boost/asio/detail/impl/win_event.ipp>
128 #endif // defined(BOOST_ASIO_HEADER_ONLY)
130 #endif // defined(BOOST_ASIO_WINDOWS)
132 #endif // BOOST_ASIO_DETAIL_WIN_EVENT_HPP