1 //
2 // detail/impl/select_reactor.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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_IMPL_SELECT_REACTOR_HPP
12 #define ASIO_DETAIL_IMPL_SELECT_REACTOR_HPP
13
14
15 #include "asio/detail/config.hpp"
16
17 #if defined(ASIO_HAS_IOCP) || (!defined(ASIO_HAS_DEV_POLL) && !defined(ASIO_HAS_EPOLL) && !defined(ASIO_HAS_KQUEUE) && !defined(ASIO_WINDOWS_RUNTIME))
18
19 #include "asio/detail/push_options.hpp"
20
21 namespace asio {
22 namespace detail {
23
24 template <typename Time_Traits>
add_timer_queue(timer_queue<Time_Traits> & queue)25 void select_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
26 {
27 do_add_timer_queue(queue);
28 }
29
30 // Remove a timer queue from the reactor.
31 template <typename Time_Traits>
remove_timer_queue(timer_queue<Time_Traits> & queue)32 void select_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
33 {
34 do_remove_timer_queue(queue);
35 }
36
37 template <typename Time_Traits>
schedule_timer(timer_queue<Time_Traits> & queue,const typename Time_Traits::time_type & time,typename timer_queue<Time_Traits>::per_timer_data & timer,wait_op * op)38 void select_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
39 const typename Time_Traits::time_type& time,
40 typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
41 {
42 asio::detail::mutex::scoped_lock lock(mutex_);
43
44 if (shutdown_)
45 {
46 io_service_.post_immediate_completion(op, false);
47 return;
48 }
49
50 bool earliest = queue.enqueue_timer(time, timer, op);
51 io_service_.work_started();
52 if (earliest)
53 interrupter_.interrupt();
54 }
55
56 template <typename Time_Traits>
cancel_timer(timer_queue<Time_Traits> & queue,typename timer_queue<Time_Traits>::per_timer_data & timer,std::size_t max_cancelled)57 std::size_t select_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
58 typename timer_queue<Time_Traits>::per_timer_data& timer,
59 std::size_t max_cancelled)
60 {
61 asio::detail::mutex::scoped_lock lock(mutex_);
62 op_queue<operation> ops;
63 std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
64 lock.unlock();
65 io_service_.post_deferred_completions(ops);
66 return n;
67 }
68
69 } // namespace detail
70 } // namespace asio
71
72 #include "asio/detail/pop_options.hpp"
73
74 #endif // defined(ASIO_HAS_IOCP)
75 // || (!defined(ASIO_HAS_DEV_POLL)
76 // && !defined(ASIO_HAS_EPOLL)
77 // && !defined(ASIO_HAS_KQUEUE)
78 // && !defined(ASIO_WINDOWS_RUNTIME))
79
80 #endif // ASIO_DETAIL_IMPL_SELECT_REACTOR_HPP
81