]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/impl/win_iocp_io_context.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / impl / win_iocp_io_context.hpp
1 //
2 // detail/impl/win_iocp_io_context.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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_IMPL_WIN_IOCP_IO_CONTEXT_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_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
22 #include <boost/asio/detail/completion_handler.hpp>
23 #include <boost/asio/detail/fenced_block.hpp>
24 #include <boost/asio/detail/handler_alloc_helpers.hpp>
25 #include <boost/asio/detail/handler_invoke_helpers.hpp>
26 #include <boost/asio/detail/memory.hpp>
27
28 #include <boost/asio/detail/push_options.hpp>
29
30 namespace boost {
31 namespace asio {
32 namespace detail {
33
34 template <typename Time_Traits>
35 void win_iocp_io_context::add_timer_queue(
36 timer_queue<Time_Traits>& queue)
37 {
38 do_add_timer_queue(queue);
39 }
40
41 template <typename Time_Traits>
42 void win_iocp_io_context::remove_timer_queue(
43 timer_queue<Time_Traits>& queue)
44 {
45 do_remove_timer_queue(queue);
46 }
47
48 template <typename Time_Traits>
49 void win_iocp_io_context::schedule_timer(timer_queue<Time_Traits>& queue,
50 const typename Time_Traits::time_type& time,
51 typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
52 {
53 // If the service has been shut down we silently discard the timer.
54 if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
55 {
56 post_immediate_completion(op, false);
57 return;
58 }
59
60 mutex::scoped_lock lock(dispatch_mutex_);
61
62 bool earliest = queue.enqueue_timer(time, timer, op);
63 work_started();
64 if (earliest)
65 update_timeout();
66 }
67
68 template <typename Time_Traits>
69 std::size_t win_iocp_io_context::cancel_timer(timer_queue<Time_Traits>& queue,
70 typename timer_queue<Time_Traits>::per_timer_data& timer,
71 std::size_t max_cancelled)
72 {
73 // If the service has been shut down we silently ignore the cancellation.
74 if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
75 return 0;
76
77 mutex::scoped_lock lock(dispatch_mutex_);
78 op_queue<win_iocp_operation> ops;
79 std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
80 post_deferred_completions(ops);
81 return n;
82 }
83
84 template <typename Time_Traits>
85 void win_iocp_io_context::move_timer(timer_queue<Time_Traits>& queue,
86 typename timer_queue<Time_Traits>::per_timer_data& to,
87 typename timer_queue<Time_Traits>::per_timer_data& from)
88 {
89 boost::asio::detail::mutex::scoped_lock lock(dispatch_mutex_);
90 op_queue<operation> ops;
91 queue.cancel_timer(to, ops);
92 queue.move_timer(to, from);
93 lock.unlock();
94 post_deferred_completions(ops);
95 }
96
97 } // namespace detail
98 } // namespace asio
99 } // namespace boost
100
101 #include <boost/asio/detail/pop_options.hpp>
102
103 #endif // defined(BOOST_ASIO_HAS_IOCP)
104
105 #endif // BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP