Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:35

0001 //
0002 // detail/impl/win_iocp_io_context.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP
0012 #define BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #if defined(BOOST_ASIO_HAS_IOCP)
0021 
0022 #include <boost/asio/detail/completion_handler.hpp>
0023 #include <boost/asio/detail/fenced_block.hpp>
0024 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0025 #include <boost/asio/detail/memory.hpp>
0026 
0027 #include <boost/asio/detail/push_options.hpp>
0028 
0029 namespace boost {
0030 namespace asio {
0031 namespace detail {
0032 
0033 template <typename Time_Traits>
0034 void win_iocp_io_context::add_timer_queue(
0035     timer_queue<Time_Traits>& queue)
0036 {
0037   do_add_timer_queue(queue);
0038 }
0039 
0040 template <typename Time_Traits>
0041 void win_iocp_io_context::remove_timer_queue(
0042     timer_queue<Time_Traits>& queue)
0043 {
0044   do_remove_timer_queue(queue);
0045 }
0046 
0047 template <typename Time_Traits>
0048 void win_iocp_io_context::schedule_timer(timer_queue<Time_Traits>& queue,
0049     const typename Time_Traits::time_type& time,
0050     typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
0051 {
0052   // If the service has been shut down we silently discard the timer.
0053   if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
0054   {
0055     post_immediate_completion(op, false);
0056     return;
0057   }
0058 
0059   mutex::scoped_lock lock(dispatch_mutex_);
0060 
0061   bool earliest = queue.enqueue_timer(time, timer, op);
0062   work_started();
0063   if (earliest)
0064     update_timeout();
0065 }
0066 
0067 template <typename Time_Traits>
0068 std::size_t win_iocp_io_context::cancel_timer(timer_queue<Time_Traits>& queue,
0069     typename timer_queue<Time_Traits>::per_timer_data& timer,
0070     std::size_t max_cancelled)
0071 {
0072   // If the service has been shut down we silently ignore the cancellation.
0073   if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
0074     return 0;
0075 
0076   mutex::scoped_lock lock(dispatch_mutex_);
0077   op_queue<win_iocp_operation> ops;
0078   std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
0079   lock.unlock();
0080   post_deferred_completions(ops);
0081   return n;
0082 }
0083 
0084 template <typename Time_Traits>
0085 void win_iocp_io_context::cancel_timer_by_key(timer_queue<Time_Traits>& queue,
0086     typename timer_queue<Time_Traits>::per_timer_data* timer,
0087     void* cancellation_key)
0088 {
0089   // If the service has been shut down we silently ignore the cancellation.
0090   if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
0091     return;
0092 
0093   mutex::scoped_lock lock(dispatch_mutex_);
0094   op_queue<win_iocp_operation> ops;
0095   queue.cancel_timer_by_key(timer, ops, cancellation_key);
0096   lock.unlock();
0097   post_deferred_completions(ops);
0098 }
0099 
0100 template <typename Time_Traits>
0101 void win_iocp_io_context::move_timer(timer_queue<Time_Traits>& queue,
0102     typename timer_queue<Time_Traits>::per_timer_data& to,
0103     typename timer_queue<Time_Traits>::per_timer_data& from)
0104 {
0105   boost::asio::detail::mutex::scoped_lock lock(dispatch_mutex_);
0106   op_queue<operation> ops;
0107   queue.cancel_timer(to, ops);
0108   queue.move_timer(to, from);
0109   lock.unlock();
0110   post_deferred_completions(ops);
0111 }
0112 
0113 } // namespace detail
0114 } // namespace asio
0115 } // namespace boost
0116 
0117 #include <boost/asio/detail/pop_options.hpp>
0118 
0119 #endif // defined(BOOST_ASIO_HAS_IOCP)
0120 
0121 #endif // BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP