Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-29 08:38:22

0001 //
0002 // detail/impl/select_reactor.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 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_SELECT_REACTOR_HPP
0012 #define BOOST_ASIO_DETAIL_IMPL_SELECT_REACTOR_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   || (!defined(BOOST_ASIO_HAS_DEV_POLL) \
0022       && !defined(BOOST_ASIO_HAS_EPOLL) \
0023       && !defined(BOOST_ASIO_HAS_KQUEUE) \
0024       && !defined(BOOST_ASIO_WINDOWS_RUNTIME))
0025 
0026 #if defined(BOOST_ASIO_HAS_IOCP)
0027 # include <boost/asio/detail/win_iocp_io_context.hpp>
0028 #else // defined(BOOST_ASIO_HAS_IOCP)
0029 # include <boost/asio/detail/scheduler.hpp>
0030 #endif // defined(BOOST_ASIO_HAS_IOCP)
0031 
0032 #include <boost/asio/detail/push_options.hpp>
0033 
0034 namespace boost {
0035 namespace asio {
0036 namespace detail {
0037 
0038 inline void select_reactor::post_immediate_completion(
0039     operation* op, bool is_continuation) const
0040 {
0041   scheduler_.post_immediate_completion(op, is_continuation);
0042 }
0043 
0044 template <typename TimeTraits, typename Allocator>
0045 void select_reactor::add_timer_queue(
0046     timer_queue<TimeTraits, Allocator>& queue)
0047 {
0048   do_add_timer_queue(queue);
0049 }
0050 
0051 // Remove a timer queue from the reactor.
0052 template <typename TimeTraits, typename Allocator>
0053 void select_reactor::remove_timer_queue(
0054     timer_queue<TimeTraits, Allocator>& queue)
0055 {
0056   do_remove_timer_queue(queue);
0057 }
0058 
0059 template <typename TimeTraits, typename Allocator>
0060 void select_reactor::schedule_timer(
0061     timer_queue<TimeTraits, Allocator>& queue,
0062     const typename TimeTraits::time_type& time,
0063     typename timer_queue<TimeTraits, Allocator>::per_timer_data& timer,
0064     wait_op* op)
0065 {
0066   boost::asio::detail::mutex::scoped_lock lock(mutex_);
0067 
0068   if (shutdown_)
0069   {
0070     scheduler_.post_immediate_completion(op, false);
0071     return;
0072   }
0073 
0074   bool earliest = queue.enqueue_timer(time, timer, op);
0075   scheduler_.work_started();
0076   if (earliest)
0077     interrupter_.interrupt();
0078 }
0079 
0080 template <typename TimeTraits, typename Allocator>
0081 std::size_t select_reactor::cancel_timer(
0082     timer_queue<TimeTraits, Allocator>& queue,
0083     typename timer_queue<TimeTraits, Allocator>::per_timer_data& timer,
0084     std::size_t max_cancelled)
0085 {
0086   boost::asio::detail::mutex::scoped_lock lock(mutex_);
0087   op_queue<operation> ops;
0088   std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
0089   lock.unlock();
0090   scheduler_.post_deferred_completions(ops);
0091   return n;
0092 }
0093 
0094 template <typename TimeTraits, typename Allocator>
0095 void select_reactor::cancel_timer_by_key(
0096     timer_queue<TimeTraits, Allocator>& queue,
0097     typename timer_queue<TimeTraits, Allocator>::per_timer_data* timer,
0098     void* cancellation_key)
0099 {
0100   mutex::scoped_lock lock(mutex_);
0101   op_queue<operation> ops;
0102   queue.cancel_timer_by_key(timer, ops, cancellation_key);
0103   lock.unlock();
0104   scheduler_.post_deferred_completions(ops);
0105 }
0106 
0107 template <typename TimeTraits, typename Allocator>
0108 void select_reactor::move_timer(timer_queue<TimeTraits, Allocator>& queue,
0109     typename timer_queue<TimeTraits, Allocator>::per_timer_data& target,
0110     typename timer_queue<TimeTraits, Allocator>::per_timer_data& source)
0111 {
0112   boost::asio::detail::mutex::scoped_lock lock(mutex_);
0113   op_queue<operation> ops;
0114   queue.cancel_timer(target, ops);
0115   queue.move_timer(target, source);
0116   lock.unlock();
0117   scheduler_.post_deferred_completions(ops);
0118 }
0119 
0120 } // namespace detail
0121 } // namespace asio
0122 } // namespace boost
0123 
0124 #include <boost/asio/detail/pop_options.hpp>
0125 
0126 #endif // defined(BOOST_ASIO_HAS_IOCP)
0127        //   || (!defined(BOOST_ASIO_HAS_DEV_POLL)
0128        //       && !defined(BOOST_ASIO_HAS_EPOLL)
0129        //       && !defined(BOOST_ASIO_HAS_KQUEUE)
0130        //       && !defined(BOOST_ASIO_WINDOWS_RUNTIME))
0131 
0132 #endif // BOOST_ASIO_DETAIL_IMPL_SELECT_REACTOR_HPP