Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // detail/impl/epoll_reactor.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_EPOLL_REACTOR_HPP
0012 #define BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #if defined(BOOST_ASIO_HAS_EPOLL)
0019 
0020 #include <boost/asio/detail/scheduler.hpp>
0021 
0022 #include <boost/asio/detail/push_options.hpp>
0023 
0024 namespace boost {
0025 namespace asio {
0026 namespace detail {
0027 
0028 inline void epoll_reactor::post_immediate_completion(
0029     operation* op, bool is_continuation) const
0030 {
0031   scheduler_.post_immediate_completion(op, is_continuation);
0032 }
0033 
0034 template <typename Time_Traits>
0035 void epoll_reactor::add_timer_queue(timer_queue<Time_Traits>& queue)
0036 {
0037   do_add_timer_queue(queue);
0038 }
0039 
0040 template <typename Time_Traits>
0041 void epoll_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue)
0042 {
0043   do_remove_timer_queue(queue);
0044 }
0045 
0046 template <typename Time_Traits>
0047 void epoll_reactor::schedule_timer(timer_queue<Time_Traits>& queue,
0048     const typename Time_Traits::time_type& time,
0049     typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
0050 {
0051   mutex::scoped_lock lock(mutex_);
0052 
0053   if (shutdown_)
0054   {
0055     scheduler_.post_immediate_completion(op, false);
0056     return;
0057   }
0058 
0059   bool earliest = queue.enqueue_timer(time, timer, op);
0060   scheduler_.work_started();
0061   if (earliest)
0062     update_timeout();
0063 }
0064 
0065 template <typename Time_Traits>
0066 std::size_t epoll_reactor::cancel_timer(timer_queue<Time_Traits>& queue,
0067     typename timer_queue<Time_Traits>::per_timer_data& timer,
0068     std::size_t max_cancelled)
0069 {
0070   mutex::scoped_lock lock(mutex_);
0071   op_queue<operation> ops;
0072   std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
0073   lock.unlock();
0074   scheduler_.post_deferred_completions(ops);
0075   return n;
0076 }
0077 
0078 template <typename Time_Traits>
0079 void epoll_reactor::cancel_timer_by_key(timer_queue<Time_Traits>& queue,
0080     typename timer_queue<Time_Traits>::per_timer_data* timer,
0081     void* cancellation_key)
0082 {
0083   mutex::scoped_lock lock(mutex_);
0084   op_queue<operation> ops;
0085   queue.cancel_timer_by_key(timer, ops, cancellation_key);
0086   lock.unlock();
0087   scheduler_.post_deferred_completions(ops);
0088 }
0089 
0090 template <typename Time_Traits>
0091 void epoll_reactor::move_timer(timer_queue<Time_Traits>& queue,
0092     typename timer_queue<Time_Traits>::per_timer_data& target,
0093     typename timer_queue<Time_Traits>::per_timer_data& source)
0094 {
0095   mutex::scoped_lock lock(mutex_);
0096   op_queue<operation> ops;
0097   queue.cancel_timer(target, ops);
0098   queue.move_timer(target, source);
0099   lock.unlock();
0100   scheduler_.post_deferred_completions(ops);
0101 }
0102 
0103 } // namespace detail
0104 } // namespace asio
0105 } // namespace boost
0106 
0107 #include <boost/asio/detail/pop_options.hpp>
0108 
0109 #endif // defined(BOOST_ASIO_HAS_EPOLL)
0110 
0111 #endif // BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP