win_event.hpp
Go to the documentation of this file.
00001 //
00002 // win_event.hpp
00003 // ~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef ASIO_DETAIL_WIN_EVENT_HPP
00012 #define ASIO_DETAIL_WIN_EVENT_HPP
00013 
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017 
00018 #include "asio/detail/push_options.hpp"
00019 
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/config.hpp>
00022 #include "asio/detail/pop_options.hpp"
00023 
00024 #if defined(BOOST_WINDOWS)
00025 
00026 #include "asio/error.hpp"
00027 #include "asio/system_error.hpp"
00028 #include "asio/detail/noncopyable.hpp"
00029 #include "asio/detail/socket_types.hpp"
00030 
00031 #include "asio/detail/push_options.hpp"
00032 #include <boost/assert.hpp>
00033 #include <boost/throw_exception.hpp>
00034 #include "asio/detail/pop_options.hpp"
00035 
00036 namespace asio {
00037 namespace detail {
00038 
00039 class win_event
00040   : private noncopyable
00041 {
00042 public:
00043   // Constructor.
00044   win_event()
00045     : event_(::CreateEvent(0, true, false, 0))
00046   {
00047     if (!event_)
00048     {
00049       DWORD last_error = ::GetLastError();
00050       asio::system_error e(
00051           asio::error_code(last_error,
00052             asio::error::get_system_category()),
00053           "event");
00054       boost::throw_exception(e);
00055     }
00056   }
00057 
00058   // Destructor.
00059   ~win_event()
00060   {
00061     ::CloseHandle(event_);
00062   }
00063 
00064   // Signal the event.
00065   template <typename Lock>
00066   void signal(Lock& lock)
00067   {
00068     BOOST_ASSERT(lock.locked());
00069     (void)lock;
00070     ::SetEvent(event_);
00071   }
00072 
00073   // Reset the event.
00074   template <typename Lock>
00075   void clear(Lock& lock)
00076   {
00077     BOOST_ASSERT(lock.locked());
00078     (void)lock;
00079     ::ResetEvent(event_);
00080   }
00081 
00082   // Wait for the event to become signalled.
00083   template <typename Lock>
00084   void wait(Lock& lock)
00085   {
00086     BOOST_ASSERT(lock.locked());
00087     lock.unlock();
00088     ::WaitForSingleObject(event_, INFINITE);
00089     lock.lock();
00090   }
00091 
00092 private:
00093   HANDLE event_;
00094 };
00095 
00096 } // namespace detail
00097 } // namespace asio
00098 
00099 #endif // defined(BOOST_WINDOWS)
00100 
00101 #include "asio/detail/pop_options.hpp"
00102 
00103 #endif // ASIO_DETAIL_WIN_EVENT_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39