~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/detail/win_event.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
//
10
 
 
11
 
#ifndef ASIO_DETAIL_WIN_EVENT_HPP
12
 
#define ASIO_DETAIL_WIN_EVENT_HPP
13
 
 
14
 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
 
# pragma once
16
 
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
 
 
18
 
#include "asio/detail/push_options.hpp"
19
 
 
20
 
#include "asio/detail/push_options.hpp"
21
 
#include <boost/config.hpp>
22
 
#include "asio/detail/pop_options.hpp"
23
 
 
24
 
#if defined(BOOST_WINDOWS)
25
 
 
26
 
#include "asio/error.hpp"
27
 
#include "asio/system_error.hpp"
28
 
#include "asio/detail/noncopyable.hpp"
29
 
#include "asio/detail/socket_types.hpp"
30
 
 
31
 
#include "asio/detail/push_options.hpp"
32
 
#include <boost/assert.hpp>
33
 
#include <boost/throw_exception.hpp>
34
 
#include "asio/detail/pop_options.hpp"
35
 
 
36
 
namespace asio {
37
 
namespace detail {
38
 
 
39
 
class win_event
40
 
  : private noncopyable
41
 
{
42
 
public:
43
 
  // Constructor.
44
 
  win_event()
45
 
    : event_(::CreateEvent(0, true, false, 0))
46
 
  {
47
 
    if (!event_)
48
 
    {
49
 
      DWORD last_error = ::GetLastError();
50
 
      asio::system_error e(
51
 
          asio::error_code(last_error,
52
 
            asio::error::get_system_category()),
53
 
          "event");
54
 
      boost::throw_exception(e);
55
 
    }
56
 
  }
57
 
 
58
 
  // Destructor.
59
 
  ~win_event()
60
 
  {
61
 
    ::CloseHandle(event_);
62
 
  }
63
 
 
64
 
  // Signal the event.
65
 
  template <typename Lock>
66
 
  void signal(Lock& lock)
67
 
  {
68
 
    BOOST_ASSERT(lock.locked());
69
 
    (void)lock;
70
 
    ::SetEvent(event_);
71
 
  }
72
 
 
73
 
  // Reset the event.
74
 
  template <typename Lock>
75
 
  void clear(Lock& lock)
76
 
  {
77
 
    BOOST_ASSERT(lock.locked());
78
 
    (void)lock;
79
 
    ::ResetEvent(event_);
80
 
  }
81
 
 
82
 
  // Wait for the event to become signalled.
83
 
  template <typename Lock>
84
 
  void wait(Lock& lock)
85
 
  {
86
 
    BOOST_ASSERT(lock.locked());
87
 
    lock.unlock();
88
 
    ::WaitForSingleObject(event_, INFINITE);
89
 
    lock.lock();
90
 
  }
91
 
 
92
 
private:
93
 
  HANDLE event_;
94
 
};
95
 
 
96
 
} // namespace detail
97
 
} // namespace asio
98
 
 
99
 
#endif // defined(BOOST_WINDOWS)
100
 
 
101
 
#include "asio/detail/pop_options.hpp"
102
 
 
103
 
#endif // ASIO_DETAIL_WIN_EVENT_HPP