comparison DEPENDENCIES/generic/include/boost/asio/detail/posix_event.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 //
2 // detail/posix_event.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2013 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 BOOST_ASIO_DETAIL_POSIX_EVENT_HPP
12 #define BOOST_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 <boost/asio/detail/config.hpp>
19
20 #if defined(BOOST_ASIO_HAS_PTHREADS)
21
22 #include <pthread.h>
23 #include <boost/asio/detail/assert.hpp>
24 #include <boost/asio/detail/noncopyable.hpp>
25
26 #include <boost/asio/detail/push_options.hpp>
27
28 namespace boost {
29 namespace asio {
30 namespace detail {
31
32 class posix_event
33 : private noncopyable
34 {
35 public:
36 // Constructor.
37 BOOST_ASIO_DECL posix_event();
38
39 // Destructor.
40 ~posix_event()
41 {
42 ::pthread_cond_destroy(&cond_);
43 }
44
45 // Signal the event.
46 template <typename Lock>
47 void signal(Lock& lock)
48 {
49 BOOST_ASIO_ASSERT(lock.locked());
50 (void)lock;
51 signalled_ = true;
52 ::pthread_cond_signal(&cond_); // Ignore EINVAL.
53 }
54
55 // Signal the event and unlock the mutex.
56 template <typename Lock>
57 void signal_and_unlock(Lock& lock)
58 {
59 BOOST_ASIO_ASSERT(lock.locked());
60 signalled_ = true;
61 lock.unlock();
62 ::pthread_cond_signal(&cond_); // Ignore EINVAL.
63 }
64
65 // Reset the event.
66 template <typename Lock>
67 void clear(Lock& lock)
68 {
69 BOOST_ASIO_ASSERT(lock.locked());
70 (void)lock;
71 signalled_ = false;
72 }
73
74 // Wait for the event to become signalled.
75 template <typename Lock>
76 void wait(Lock& lock)
77 {
78 BOOST_ASIO_ASSERT(lock.locked());
79 while (!signalled_)
80 ::pthread_cond_wait(&cond_, &lock.mutex().mutex_); // Ignore EINVAL.
81 }
82
83 private:
84 ::pthread_cond_t cond_;
85 bool signalled_;
86 };
87
88 } // namespace detail
89 } // namespace asio
90 } // namespace boost
91
92 #include <boost/asio/detail/pop_options.hpp>
93
94 #if defined(BOOST_ASIO_HEADER_ONLY)
95 # include <boost/asio/detail/impl/posix_event.ipp>
96 #endif // defined(BOOST_ASIO_HEADER_ONLY)
97
98 #endif // defined(BOOST_ASIO_HAS_PTHREADS)
99
100 #endif // BOOST_ASIO_DETAIL_POSIX_EVENT_HPP