Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / asio / detail / impl / kqueue_reactor.hpp
1 //
2 // detail/impl/kqueue_reactor.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2005 Stefan Arentz (stefan at soze dot com)
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 //
11
12 #ifndef BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP
13 #define BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP
14
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
19 #include <boost/asio/detail/config.hpp>
20
21 #if defined(BOOST_ASIO_HAS_KQUEUE)
22
23 #include <boost/asio/detail/push_options.hpp>
24
25 namespace boost {
26 namespace asio {
27 namespace detail {
28
29 template <typename Time_Traits>
30 void kqueue_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
31 {
32   do_add_timer_queue(queue);
33 }
34
35 // Remove a timer queue from the reactor.
36 template <typename Time_Traits>
37 void kqueue_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
38 {
39   do_remove_timer_queue(queue);
40 }
41
42 template <typename Time_Traits>
43 void kqueue_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
44     const typename Time_Traits::time_type& time,
45     typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
46 {
47   boost::asio::detail::mutex::scoped_lock lock(mutex_);
48
49   if (shutdown_)
50   {
51     io_service_.post_immediate_completion(op, false);
52     return;
53   }
54
55   bool earliest = queue.enqueue_timer(time, timer, op);
56   io_service_.work_started();
57   if (earliest)
58     interrupt();
59 }
60
61 template <typename Time_Traits>
62 std::size_t kqueue_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
63     typename timer_queue<Time_Traits>::per_timer_data& timer,
64     std::size_t max_cancelled)
65 {
66   boost::asio::detail::mutex::scoped_lock lock(mutex_);
67   op_queue<operation> ops;
68   std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
69   lock.unlock();
70   io_service_.post_deferred_completions(ops);
71   return n;
72 }
73
74 } // namespace detail
75 } // namespace asio
76 } // namespace boost
77
78 #include <boost/asio/detail/pop_options.hpp>
79
80 #endif // defined(BOOST_ASIO_HAS_KQUEUE)
81
82 #endif // BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP