diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:11:01 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:11:01 +0900 |
commit | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (patch) | |
tree | 5c1733853892b8397d67706fa453a9bd978d2102 /boost/asio/detail/impl/select_reactor.ipp | |
parent | 88e602c57797660ebe0f9e15dbd64c1ff16dead3 (diff) | |
download | boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.gz boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.bz2 boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.zip |
Imported Upstream version 1.66.0upstream/1.66.0
Diffstat (limited to 'boost/asio/detail/impl/select_reactor.ipp')
-rw-r--r-- | boost/asio/detail/impl/select_reactor.ipp | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/boost/asio/detail/impl/select_reactor.ipp b/boost/asio/detail/impl/select_reactor.ipp index 869f73492b..44fab64269 100644 --- a/boost/asio/detail/impl/select_reactor.ipp +++ b/boost/asio/detail/impl/select_reactor.ipp @@ -23,7 +23,6 @@ && !defined(BOOST_ASIO_HAS_KQUEUE) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME)) -#include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fd_set_adapter.hpp> #include <boost/asio/detail/select_reactor.hpp> #include <boost/asio/detail/signal_blocker.hpp> @@ -35,9 +34,28 @@ namespace boost { namespace asio { namespace detail { -select_reactor::select_reactor(boost::asio::io_service& io_service) - : boost::asio::detail::service_base<select_reactor>(io_service), - io_service_(use_service<io_service_impl>(io_service)), +#if defined(BOOST_ASIO_HAS_IOCP) +class select_reactor::thread_function +{ +public: + explicit thread_function(select_reactor* r) + : this_(r) + { + } + + void operator()() + { + this_->run_thread(); + } + +private: + select_reactor* this_; +}; +#endif // defined(BOOST_ASIO_HAS_IOCP) + +select_reactor::select_reactor(boost::asio::execution_context& ctx) + : execution_context_service_base<select_reactor>(ctx), + scheduler_(use_service<scheduler_type>(ctx)), mutex_(), interrupter_(), #if defined(BOOST_ASIO_HAS_IOCP) @@ -48,17 +66,16 @@ select_reactor::select_reactor(boost::asio::io_service& io_service) { #if defined(BOOST_ASIO_HAS_IOCP) boost::asio::detail::signal_blocker sb; - thread_ = new boost::asio::detail::thread( - bind_handler(&select_reactor::call_run_thread, this)); + thread_ = new boost::asio::detail::thread(thread_function(this)); #endif // defined(BOOST_ASIO_HAS_IOCP) } select_reactor::~select_reactor() { - shutdown_service(); + shutdown(); } -void select_reactor::shutdown_service() +void select_reactor::shutdown() { boost::asio::detail::mutex::scoped_lock lock(mutex_); shutdown_ = true; @@ -84,18 +101,19 @@ void select_reactor::shutdown_service() timer_queues_.get_all_timers(ops); - io_service_.abandon_operations(ops); + scheduler_.abandon_operations(ops); } -void select_reactor::fork_service(boost::asio::io_service::fork_event fork_ev) +void select_reactor::notify_fork( + boost::asio::execution_context::fork_event fork_ev) { - if (fork_ev == boost::asio::io_service::fork_child) + if (fork_ev == boost::asio::execution_context::fork_child) interrupter_.recreate(); } void select_reactor::init_task() { - io_service_.init_task(); + scheduler_.init_task(); } int select_reactor::register_descriptor(socket_type, @@ -135,7 +153,7 @@ void select_reactor::start_op(int op_type, socket_type descriptor, } bool first = op_queue_[op_type].enqueue_operation(descriptor, op); - io_service_.work_started(); + scheduler_.work_started(); if (first) interrupter_.interrupt(); } @@ -168,7 +186,7 @@ void select_reactor::cleanup_descriptor_data( { } -void select_reactor::run(bool block, op_queue<operation>& ops) +void select_reactor::run(long usec, op_queue<operation>& ops) { boost::asio::detail::mutex::scoped_lock lock(mutex_); @@ -205,12 +223,12 @@ void select_reactor::run(bool block, op_queue<operation>& ops) // We can return immediately if there's no work to do and the reactor is // not supposed to block. - if (!block && !have_work_to_do) + if (!usec && !have_work_to_do) return; // Determine how long to block while waiting for events. timeval tv_buf = { 0, 0 }; - timeval* tv = block ? get_timeout(tv_buf) : &tv_buf; + timeval* tv = usec ? get_timeout(usec, tv_buf) : &tv_buf; lock.unlock(); @@ -259,15 +277,10 @@ void select_reactor::run_thread() lock.unlock(); op_queue<operation> ops; run(true, ops); - io_service_.post_deferred_completions(ops); + scheduler_.post_deferred_completions(ops); lock.lock(); } } - -void select_reactor::call_run_thread(select_reactor* reactor) -{ - reactor->run_thread(); -} #endif // defined(BOOST_ASIO_HAS_IOCP) void select_reactor::do_add_timer_queue(timer_queue_base& queue) @@ -282,11 +295,13 @@ void select_reactor::do_remove_timer_queue(timer_queue_base& queue) timer_queues_.erase(&queue); } -timeval* select_reactor::get_timeout(timeval& tv) +timeval* select_reactor::get_timeout(long usec, timeval& tv) { // By default we will wait no longer than 5 minutes. This will ensure that // any changes to the system clock are detected after no longer than this. - long usec = timer_queues_.wait_duration_usec(5 * 60 * 1000 * 1000); + const long max_usec = 5 * 60 * 1000 * 1000; + usec = timer_queues_.wait_duration_usec( + (usec < 0 || max_usec < usec) ? max_usec : usec); tv.tv_sec = usec / 1000000; tv.tv_usec = usec % 1000000; return &tv; @@ -300,7 +315,7 @@ void select_reactor::cancel_ops_unlocked(socket_type descriptor, for (int i = 0; i < max_ops; ++i) need_interrupt = op_queue_[i].cancel_operations( descriptor, ops, ec) || need_interrupt; - io_service_.post_deferred_completions(ops); + scheduler_.post_deferred_completions(ops); if (need_interrupt) interrupter_.interrupt(); } |