2 // detail/impl/win_iocp_io_context.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_IOCP)
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>
28 #include <boost/asio/detail/push_options.hpp>
34 template <typename Time_Traits>
35 void win_iocp_io_context::add_timer_queue(
36 timer_queue<Time_Traits>& queue)
38 do_add_timer_queue(queue);
41 template <typename Time_Traits>
42 void win_iocp_io_context::remove_timer_queue(
43 timer_queue<Time_Traits>& queue)
45 do_remove_timer_queue(queue);
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)
53 // If the service has been shut down we silently discard the timer.
54 if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
56 post_immediate_completion(op, false);
60 mutex::scoped_lock lock(dispatch_mutex_);
62 bool earliest = queue.enqueue_timer(time, timer, op);
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)
73 // If the service has been shut down we silently ignore the cancellation.
74 if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
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);
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)
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);
94 post_deferred_completions(ops);
101 #include <boost/asio/detail/pop_options.hpp>
103 #endif // defined(BOOST_ASIO_HAS_IOCP)
105 #endif // BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP