]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/impl/select_reactor.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
11fdf7f2 | 5 | // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
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_IMPL_SELECT_REACTOR_HPP | |
12 | #define BOOST_ASIO_DETAIL_IMPL_SELECT_REACTOR_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_IOCP) \ | |
21 | || (!defined(BOOST_ASIO_HAS_DEV_POLL) \ | |
22 | && !defined(BOOST_ASIO_HAS_EPOLL) \ | |
23 | && !defined(BOOST_ASIO_HAS_KQUEUE) \ | |
24 | && !defined(BOOST_ASIO_WINDOWS_RUNTIME)) | |
25 | ||
26 | #include <boost/asio/detail/push_options.hpp> | |
27 | ||
28 | namespace boost { | |
29 | namespace asio { | |
30 | namespace detail { | |
31 | ||
32 | template <typename Time_Traits> | |
33 | void select_reactor::add_timer_queue(timer_queue<Time_Traits>& queue) | |
34 | { | |
35 | do_add_timer_queue(queue); | |
36 | } | |
37 | ||
38 | // Remove a timer queue from the reactor. | |
39 | template <typename Time_Traits> | |
40 | void select_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue) | |
41 | { | |
42 | do_remove_timer_queue(queue); | |
43 | } | |
44 | ||
45 | template <typename Time_Traits> | |
46 | void select_reactor::schedule_timer(timer_queue<Time_Traits>& queue, | |
47 | const typename Time_Traits::time_type& time, | |
48 | typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op) | |
49 | { | |
50 | boost::asio::detail::mutex::scoped_lock lock(mutex_); | |
51 | ||
52 | if (shutdown_) | |
53 | { | |
b32b8144 | 54 | scheduler_.post_immediate_completion(op, false); |
7c673cae FG |
55 | return; |
56 | } | |
57 | ||
58 | bool earliest = queue.enqueue_timer(time, timer, op); | |
b32b8144 | 59 | scheduler_.work_started(); |
7c673cae FG |
60 | if (earliest) |
61 | interrupter_.interrupt(); | |
62 | } | |
63 | ||
64 | template <typename Time_Traits> | |
65 | std::size_t select_reactor::cancel_timer(timer_queue<Time_Traits>& queue, | |
66 | typename timer_queue<Time_Traits>::per_timer_data& timer, | |
67 | std::size_t max_cancelled) | |
68 | { | |
69 | boost::asio::detail::mutex::scoped_lock lock(mutex_); | |
70 | op_queue<operation> ops; | |
71 | std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); | |
72 | lock.unlock(); | |
b32b8144 | 73 | scheduler_.post_deferred_completions(ops); |
7c673cae FG |
74 | return n; |
75 | } | |
76 | ||
b32b8144 FG |
77 | template <typename Time_Traits> |
78 | void select_reactor::move_timer(timer_queue<Time_Traits>& queue, | |
79 | typename timer_queue<Time_Traits>::per_timer_data& target, | |
80 | typename timer_queue<Time_Traits>::per_timer_data& source) | |
81 | { | |
82 | boost::asio::detail::mutex::scoped_lock lock(mutex_); | |
83 | op_queue<operation> ops; | |
84 | queue.cancel_timer(target, ops); | |
85 | queue.move_timer(target, source); | |
86 | lock.unlock(); | |
87 | scheduler_.post_deferred_completions(ops); | |
88 | } | |
89 | ||
7c673cae FG |
90 | } // namespace detail |
91 | } // namespace asio | |
92 | } // namespace boost | |
93 | ||
94 | #include <boost/asio/detail/pop_options.hpp> | |
95 | ||
96 | #endif // defined(BOOST_ASIO_HAS_IOCP) | |
97 | // || (!defined(BOOST_ASIO_HAS_DEV_POLL) | |
98 | // && !defined(BOOST_ASIO_HAS_EPOLL) | |
99 | // && !defined(BOOST_ASIO_HAS_KQUEUE) | |
100 | // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)) | |
101 | ||
102 | #endif // BOOST_ASIO_DETAIL_IMPL_SELECT_REACTOR_HPP |