]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/impl/dev_poll_reactor.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
f67539c2 | 5 | // Copyright (c) 2003-2020 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_DEV_POLL_REACTOR_HPP | |
12 | #define BOOST_ASIO_DETAIL_IMPL_DEV_POLL_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_DEV_POLL) | |
21 | ||
22 | #include <boost/asio/detail/push_options.hpp> | |
23 | ||
24 | namespace boost { | |
25 | namespace asio { | |
26 | namespace detail { | |
27 | ||
28 | template <typename Time_Traits> | |
29 | void dev_poll_reactor::add_timer_queue(timer_queue<Time_Traits>& queue) | |
30 | { | |
31 | do_add_timer_queue(queue); | |
32 | } | |
33 | ||
34 | template <typename Time_Traits> | |
35 | void dev_poll_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue) | |
36 | { | |
37 | do_remove_timer_queue(queue); | |
38 | } | |
39 | ||
40 | template <typename Time_Traits> | |
41 | void dev_poll_reactor::schedule_timer(timer_queue<Time_Traits>& queue, | |
42 | const typename Time_Traits::time_type& time, | |
43 | typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op) | |
44 | { | |
45 | boost::asio::detail::mutex::scoped_lock lock(mutex_); | |
46 | ||
47 | if (shutdown_) | |
48 | { | |
b32b8144 | 49 | scheduler_.post_immediate_completion(op, false); |
7c673cae FG |
50 | return; |
51 | } | |
52 | ||
53 | bool earliest = queue.enqueue_timer(time, timer, op); | |
b32b8144 | 54 | scheduler_.work_started(); |
7c673cae FG |
55 | if (earliest) |
56 | interrupter_.interrupt(); | |
57 | } | |
58 | ||
59 | template <typename Time_Traits> | |
60 | std::size_t dev_poll_reactor::cancel_timer(timer_queue<Time_Traits>& queue, | |
61 | typename timer_queue<Time_Traits>::per_timer_data& timer, | |
62 | std::size_t max_cancelled) | |
63 | { | |
64 | boost::asio::detail::mutex::scoped_lock lock(mutex_); | |
65 | op_queue<operation> ops; | |
66 | std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); | |
67 | lock.unlock(); | |
b32b8144 | 68 | scheduler_.post_deferred_completions(ops); |
7c673cae FG |
69 | return n; |
70 | } | |
71 | ||
b32b8144 FG |
72 | template <typename Time_Traits> |
73 | void dev_poll_reactor::move_timer(timer_queue<Time_Traits>& queue, | |
74 | typename timer_queue<Time_Traits>::per_timer_data& target, | |
75 | typename timer_queue<Time_Traits>::per_timer_data& source) | |
76 | { | |
77 | boost::asio::detail::mutex::scoped_lock lock(mutex_); | |
78 | op_queue<operation> ops; | |
79 | queue.cancel_timer(target, ops); | |
80 | queue.move_timer(target, source); | |
81 | lock.unlock(); | |
82 | scheduler_.post_deferred_completions(ops); | |
83 | } | |
84 | ||
7c673cae FG |
85 | } // namespace detail |
86 | } // namespace asio | |
87 | } // namespace boost | |
88 | ||
89 | #include <boost/asio/detail/pop_options.hpp> | |
90 | ||
91 | #endif // defined(BOOST_ASIO_HAS_DEV_POLL) | |
92 | ||
93 | #endif // BOOST_ASIO_DETAIL_IMPL_DEV_POLL_REACTOR_HPP |