fix doc example typo
[boost.git] / boost / asio / detail / win_event.hpp
blobd0a135e4401cfd76d7fe14ce8a2d2d38f0c46428
1 //
2 // win_event.hpp
3 // ~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
11 #ifndef BOOST_ASIO_DETAIL_WIN_EVENT_HPP
12 #define BOOST_ASIO_DETAIL_WIN_EVENT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/config.hpp>
22 #include <boost/system/system_error.hpp>
23 #include <boost/asio/detail/pop_options.hpp>
25 #if defined(BOOST_WINDOWS)
27 #include <boost/asio/error.hpp>
28 #include <boost/asio/detail/noncopyable.hpp>
29 #include <boost/asio/detail/socket_types.hpp>
31 #include <boost/asio/detail/push_options.hpp>
32 #include <boost/assert.hpp>
33 #include <boost/throw_exception.hpp>
34 #include <boost/asio/detail/pop_options.hpp>
36 namespace boost {
37 namespace asio {
38 namespace detail {
40 class win_event
41 : private noncopyable
43 public:
44 // Constructor.
45 win_event()
46 : event_(::CreateEvent(0, true, false, 0))
48 if (!event_)
50 DWORD last_error = ::GetLastError();
51 boost::system::system_error e(
52 boost::system::error_code(last_error,
53 boost::asio::error::get_system_category()),
54 "event");
55 boost::throw_exception(e);
59 // Destructor.
60 ~win_event()
62 ::CloseHandle(event_);
65 // Signal the event.
66 template <typename Lock>
67 void signal(Lock& lock)
69 BOOST_ASSERT(lock.locked());
70 (void)lock;
71 ::SetEvent(event_);
74 // Reset the event.
75 template <typename Lock>
76 void clear(Lock& lock)
78 BOOST_ASSERT(lock.locked());
79 (void)lock;
80 ::ResetEvent(event_);
83 // Wait for the event to become signalled.
84 template <typename Lock>
85 void wait(Lock& lock)
87 BOOST_ASSERT(lock.locked());
88 lock.unlock();
89 ::WaitForSingleObject(event_, INFINITE);
90 lock.lock();
93 private:
94 HANDLE event_;
97 } // namespace detail
98 } // namespace asio
99 } // namespace boost
101 #endif // defined(BOOST_WINDOWS)
103 #include <boost/asio/detail/pop_options.hpp>
105 #endif // BOOST_ASIO_DETAIL_WIN_EVENT_HPP