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

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/detail/posix_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
 
// posix_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_POSIX_EVENT_HPP
12
 
#define ASIO_DETAIL_POSIX_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_HAS_PTHREADS)
25
 
 
26
 
#include "asio/detail/push_options.hpp"
27
 
#include <boost/assert.hpp>
28
 
#include <boost/throw_exception.hpp>
29
 
#include <pthread.h>
30
 
#include "asio/detail/pop_options.hpp"
31
 
 
32
 
#include "asio/error.hpp"
33
 
#include "asio/system_error.hpp"
34
 
#include "asio/detail/noncopyable.hpp"
35
 
 
36
 
namespace asio {
37
 
namespace detail {
38
 
 
39
 
class posix_event
40
 
  : private noncopyable
41
 
{
42
 
public:
43
 
  // Constructor.
44
 
  posix_event()
45
 
    : signalled_(false)
46
 
  {
47
 
    int error = ::pthread_cond_init(&cond_, 0);
48
 
    if (error != 0)
49
 
    {
50
 
      asio::system_error e(
51
 
          asio::error_code(error,
52
 
            asio::error::get_system_category()),
53
 
          "event");
54
 
      boost::throw_exception(e);
55
 
    }
56
 
  }
57
 
 
58
 
  // Destructor.
59
 
  ~posix_event()
60
 
  {
61
 
    ::pthread_cond_destroy(&cond_);
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
 
    signalled_ = true;
71
 
    ::pthread_cond_signal(&cond_); // Ignore EINVAL.
72
 
  }
73
 
 
74
 
  // Reset the event.
75
 
  template <typename Lock>
76
 
  void clear(Lock& lock)
77
 
  {
78
 
    BOOST_ASSERT(lock.locked());
79
 
    (void)lock;
80
 
    signalled_ = false;
81
 
  }
82
 
 
83
 
  // Wait for the event to become signalled.
84
 
  template <typename Lock>
85
 
  void wait(Lock& lock)
86
 
  {
87
 
    BOOST_ASSERT(lock.locked());
88
 
    while (!signalled_)
89
 
      ::pthread_cond_wait(&cond_, &lock.mutex().mutex_); // Ignore EINVAL.
90
 
  }
91
 
 
92
 
private:
93
 
  ::pthread_cond_t cond_;
94
 
  bool signalled_;
95
 
};
96
 
 
97
 
} // namespace detail
98
 
} // namespace asio
99
 
 
100
 
#endif // defined(BOOST_HAS_PTHREADS)
101
 
 
102
 
#include "asio/detail/pop_options.hpp"
103
 
 
104
 
#endif // ASIO_DETAIL_POSIX_EVENT_HPP