diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:22:41 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:22:41 +0900 |
commit | 3c1df2168531ad5580076ae08d529054689aeedd (patch) | |
tree | 941aff6f86393eecacddfec252a8508c7e8351c9 /boost/asio/detail/impl | |
parent | d6a306e745acfee00e81ccaf3324a2a03516db41 (diff) | |
download | boost-3c1df2168531ad5580076ae08d529054689aeedd.tar.gz boost-3c1df2168531ad5580076ae08d529054689aeedd.tar.bz2 boost-3c1df2168531ad5580076ae08d529054689aeedd.zip |
Imported Upstream version 1.70.0upstream/1.70.0
Diffstat (limited to 'boost/asio/detail/impl')
50 files changed, 253 insertions, 167 deletions
diff --git a/boost/asio/detail/impl/buffer_sequence_adapter.ipp b/boost/asio/detail/impl/buffer_sequence_adapter.ipp index 26708ced33..b3fb59ccc7 100644 --- a/boost/asio/detail/impl/buffer_sequence_adapter.ipp +++ b/boost/asio/detail/impl/buffer_sequence_adapter.ipp @@ -2,7 +2,7 @@ // detail/impl/buffer_sequence_adapter.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/descriptor_ops.ipp b/boost/asio/detail/impl/descriptor_ops.ipp index 1bb68be1c0..1a26e6db69 100644 --- a/boost/asio/detail/impl/descriptor_ops.ipp +++ b/boost/asio/detail/impl/descriptor_ops.ipp @@ -2,7 +2,7 @@ // detail/impl/descriptor_ops.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/dev_poll_reactor.hpp b/boost/asio/detail/impl/dev_poll_reactor.hpp index 797937bad8..87dd20ab4b 100644 --- a/boost/asio/detail/impl/dev_poll_reactor.hpp +++ b/boost/asio/detail/impl/dev_poll_reactor.hpp @@ -2,7 +2,7 @@ // detail/impl/dev_poll_reactor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/dev_poll_reactor.ipp b/boost/asio/detail/impl/dev_poll_reactor.ipp index 5cc73ca9c1..807741dc4d 100644 --- a/boost/asio/detail/impl/dev_poll_reactor.ipp +++ b/boost/asio/detail/impl/dev_poll_reactor.ipp @@ -2,7 +2,7 @@ // detail/impl/dev_poll_reactor.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/epoll_reactor.hpp b/boost/asio/detail/impl/epoll_reactor.hpp index 101b1d6ead..15968a30b3 100644 --- a/boost/asio/detail/impl/epoll_reactor.hpp +++ b/boost/asio/detail/impl/epoll_reactor.hpp @@ -2,7 +2,7 @@ // detail/impl/epoll_reactor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/epoll_reactor.ipp b/boost/asio/detail/impl/epoll_reactor.ipp index 1e9babcc14..b1e1b39d05 100644 --- a/boost/asio/detail/impl/epoll_reactor.ipp +++ b/boost/asio/detail/impl/epoll_reactor.ipp @@ -2,7 +2,7 @@ // detail/impl/epoll_reactor.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/eventfd_select_interrupter.ipp b/boost/asio/detail/impl/eventfd_select_interrupter.ipp index 8804009442..38d4b2a61d 100644 --- a/boost/asio/detail/impl/eventfd_select_interrupter.ipp +++ b/boost/asio/detail/impl/eventfd_select_interrupter.ipp @@ -2,7 +2,7 @@ // detail/impl/eventfd_select_interrupter.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Roelof Naude (roelof.naude at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/boost/asio/detail/impl/handler_tracking.ipp b/boost/asio/detail/impl/handler_tracking.ipp index b3abbb513a..c873a50987 100644 --- a/boost/asio/detail/impl/handler_tracking.ipp +++ b/boost/asio/detail/impl/handler_tracking.ipp @@ -2,7 +2,7 @@ // detail/impl/handler_tracking.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/kqueue_reactor.hpp b/boost/asio/detail/impl/kqueue_reactor.hpp index 4d79ba5d7c..f4dd174fdc 100644 --- a/boost/asio/detail/impl/kqueue_reactor.hpp +++ b/boost/asio/detail/impl/kqueue_reactor.hpp @@ -2,7 +2,7 @@ // detail/impl/kqueue_reactor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2005 Stefan Arentz (stefan at soze dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/boost/asio/detail/impl/kqueue_reactor.ipp b/boost/asio/detail/impl/kqueue_reactor.ipp index 9069ae4442..02475aaa36 100644 --- a/boost/asio/detail/impl/kqueue_reactor.ipp +++ b/boost/asio/detail/impl/kqueue_reactor.ipp @@ -2,7 +2,7 @@ // detail/impl/kqueue_reactor.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2005 Stefan Arentz (stefan at soze dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/boost/asio/detail/impl/null_event.ipp b/boost/asio/detail/impl/null_event.ipp index 19bab80b33..b7568413fb 100644 --- a/boost/asio/detail/impl/null_event.ipp +++ b/boost/asio/detail/impl/null_event.ipp @@ -2,7 +2,7 @@ // detail/impl/null_event.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/pipe_select_interrupter.ipp b/boost/asio/detail/impl/pipe_select_interrupter.ipp index bfff076747..f7bb7851b2 100644 --- a/boost/asio/detail/impl/pipe_select_interrupter.ipp +++ b/boost/asio/detail/impl/pipe_select_interrupter.ipp @@ -2,7 +2,7 @@ // detail/impl/pipe_select_interrupter.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/posix_event.ipp b/boost/asio/detail/impl/posix_event.ipp index 6f096bc08e..1c6d885a63 100644 --- a/boost/asio/detail/impl/posix_event.ipp +++ b/boost/asio/detail/impl/posix_event.ipp @@ -2,7 +2,7 @@ // detail/impl/posix_event.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/posix_mutex.ipp b/boost/asio/detail/impl/posix_mutex.ipp index 57564714a1..fc86d43815 100644 --- a/boost/asio/detail/impl/posix_mutex.ipp +++ b/boost/asio/detail/impl/posix_mutex.ipp @@ -2,7 +2,7 @@ // detail/impl/posix_mutex.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/posix_thread.ipp b/boost/asio/detail/impl/posix_thread.ipp index c2ee8efef7..d01922c625 100644 --- a/boost/asio/detail/impl/posix_thread.ipp +++ b/boost/asio/detail/impl/posix_thread.ipp @@ -2,7 +2,7 @@ // detail/impl/posix_thread.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/posix_tss_ptr.ipp b/boost/asio/detail/impl/posix_tss_ptr.ipp index a40f3f81a6..623dc679c5 100644 --- a/boost/asio/detail/impl/posix_tss_ptr.ipp +++ b/boost/asio/detail/impl/posix_tss_ptr.ipp @@ -2,7 +2,7 @@ // detail/impl/posix_tss_ptr.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/reactive_descriptor_service.ipp b/boost/asio/detail/impl/reactive_descriptor_service.ipp index 735239c597..0611a953db 100644 --- a/boost/asio/detail/impl/reactive_descriptor_service.ipp +++ b/boost/asio/detail/impl/reactive_descriptor_service.ipp @@ -2,7 +2,7 @@ // detail/impl/reactive_descriptor_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -31,9 +31,9 @@ namespace asio { namespace detail { reactive_descriptor_service::reactive_descriptor_service( - boost::asio::io_context& io_context) - : service_base<reactive_descriptor_service>(io_context), - reactor_(boost::asio::use_service<reactor>(io_context)) + execution_context& context) + : execution_context_service_base<reactive_descriptor_service>(context), + reactor_(boost::asio::use_service<reactor>(context)) { reactor_.init_task(); } diff --git a/boost/asio/detail/impl/reactive_serial_port_service.ipp b/boost/asio/detail/impl/reactive_serial_port_service.ipp index c1ff461830..62546604b4 100644 --- a/boost/asio/detail/impl/reactive_serial_port_service.ipp +++ b/boost/asio/detail/impl/reactive_serial_port_service.ipp @@ -2,7 +2,7 @@ // detail/impl/reactive_serial_port_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -31,9 +31,9 @@ namespace asio { namespace detail { reactive_serial_port_service::reactive_serial_port_service( - boost::asio::io_context& io_context) - : service_base<reactive_serial_port_service>(io_context), - descriptor_service_(io_context) + execution_context& context) + : execution_context_service_base<reactive_serial_port_service>(context), + descriptor_service_(context) { } diff --git a/boost/asio/detail/impl/reactive_socket_service_base.ipp b/boost/asio/detail/impl/reactive_socket_service_base.ipp index 6fdf437c1d..5ae4b64a6d 100644 --- a/boost/asio/detail/impl/reactive_socket_service_base.ipp +++ b/boost/asio/detail/impl/reactive_socket_service_base.ipp @@ -2,7 +2,7 @@ // detail/reactive_socket_service_base.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -29,9 +29,8 @@ namespace asio { namespace detail { reactive_socket_service_base::reactive_socket_service_base( - boost::asio::io_context& io_context) - : io_context_(io_context), - reactor_(use_service<reactor>(io_context)) + execution_context& context) + : reactor_(use_service<reactor>(context)) { reactor_.init_task(); } diff --git a/boost/asio/detail/impl/resolver_service_base.ipp b/boost/asio/detail/impl/resolver_service_base.ipp index 144e2a1753..64b92a89ac 100644 --- a/boost/asio/detail/impl/resolver_service_base.ipp +++ b/boost/asio/detail/impl/resolver_service_base.ipp @@ -2,7 +2,7 @@ // detail/impl/resolver_service_base.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -24,25 +24,30 @@ namespace boost { namespace asio { namespace detail { -class resolver_service_base::work_io_context_runner +class resolver_service_base::work_scheduler_runner { public: - work_io_context_runner(boost::asio::io_context& io_context) - : io_context_(io_context) {} - void operator()() { io_context_.run(); } + work_scheduler_runner(scheduler_impl& work_scheduler) + : work_scheduler_(work_scheduler) + { + } + + void operator()() + { + boost::system::error_code ec; + work_scheduler_.run(ec); + } + private: - boost::asio::io_context& io_context_; + scheduler_impl& work_scheduler_; }; -resolver_service_base::resolver_service_base( - boost::asio::io_context& io_context) - : io_context_impl_(boost::asio::use_service<io_context_impl>(io_context)), - work_io_context_(new boost::asio::io_context(-1)), - work_io_context_impl_(boost::asio::use_service< - io_context_impl>(*work_io_context_)), - work_(boost::asio::make_work_guard(*work_io_context_)), +resolver_service_base::resolver_service_base(execution_context& context) + : scheduler_(boost::asio::use_service<scheduler_impl>(context)), + work_scheduler_(new scheduler_impl(context, -1, false)), work_thread_(0) { + work_scheduler_->work_started(); } resolver_service_base::~resolver_service_base() @@ -52,34 +57,35 @@ resolver_service_base::~resolver_service_base() void resolver_service_base::base_shutdown() { - work_.reset(); - if (work_io_context_.get()) + if (work_scheduler_.get()) { - work_io_context_->stop(); + work_scheduler_->work_finished(); + work_scheduler_->stop(); if (work_thread_.get()) { work_thread_->join(); work_thread_.reset(); } - work_io_context_.reset(); + work_scheduler_.reset(); } } void resolver_service_base::base_notify_fork( - boost::asio::io_context::fork_event fork_ev) + execution_context::fork_event fork_ev) { if (work_thread_.get()) { - if (fork_ev == boost::asio::io_context::fork_prepare) + if (fork_ev == execution_context::fork_prepare) { - work_io_context_->stop(); + work_scheduler_->stop(); work_thread_->join(); + work_thread_.reset(); } else { - work_io_context_->restart(); + work_scheduler_->restart(); work_thread_.reset(new boost::asio::detail::thread( - work_io_context_runner(*work_io_context_))); + work_scheduler_runner(*work_scheduler_))); } } } @@ -93,7 +99,7 @@ void resolver_service_base::construct( void resolver_service_base::destroy( resolver_service_base::implementation_type& impl) { - BOOST_ASIO_HANDLER_OPERATION((io_context_impl_.context(), + BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "resolver", &impl, 0, "cancel")); impl.reset(); @@ -115,7 +121,7 @@ void resolver_service_base::move_assign(implementation_type& impl, void resolver_service_base::cancel( resolver_service_base::implementation_type& impl) { - BOOST_ASIO_HANDLER_OPERATION((io_context_impl_.context(), + BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "resolver", &impl, 0, "cancel")); impl.reset(static_cast<void*>(0), socket_ops::noop_deleter()); @@ -124,16 +130,16 @@ void resolver_service_base::cancel( void resolver_service_base::start_resolve_op(resolve_op* op) { if (BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(SCHEDULER, - io_context_impl_.concurrency_hint())) + scheduler_.concurrency_hint())) { start_work_thread(); - io_context_impl_.work_started(); - work_io_context_impl_.post_immediate_completion(op, false); + scheduler_.work_started(); + work_scheduler_->post_immediate_completion(op, false); } else { op->ec_ = boost::asio::error::operation_not_supported; - io_context_impl_.post_immediate_completion(op, false); + scheduler_.post_immediate_completion(op, false); } } @@ -143,7 +149,7 @@ void resolver_service_base::start_work_thread() if (!work_thread_.get()) { work_thread_.reset(new boost::asio::detail::thread( - work_io_context_runner(*work_io_context_))); + work_scheduler_runner(*work_scheduler_))); } } diff --git a/boost/asio/detail/impl/scheduler.ipp b/boost/asio/detail/impl/scheduler.ipp index 9dae6836ce..4ef5c86688 100644 --- a/boost/asio/detail/impl/scheduler.ipp +++ b/boost/asio/detail/impl/scheduler.ipp @@ -2,7 +2,7 @@ // detail/impl/scheduler.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -23,6 +23,7 @@ #include <boost/asio/detail/reactor.hpp> #include <boost/asio/detail/scheduler.hpp> #include <boost/asio/detail/scheduler_thread_info.hpp> +#include <boost/asio/detail/signal_blocker.hpp> #include <boost/asio/detail/push_options.hpp> @@ -30,6 +31,24 @@ namespace boost { namespace asio { namespace detail { +class scheduler::thread_function +{ +public: + explicit thread_function(scheduler* s) + : this_(s) + { + } + + void operator()() + { + boost::system::error_code ec; + this_->run(ec); + } + +private: + scheduler* this_; +}; + struct scheduler::task_cleanup { ~task_cleanup() @@ -85,8 +104,8 @@ struct scheduler::work_cleanup thread_info* this_thread_; }; -scheduler::scheduler( - boost::asio::execution_context& ctx, int concurrency_hint) +scheduler::scheduler(boost::asio::execution_context& ctx, + int concurrency_hint, bool own_thread) : boost::asio::detail::execution_context_service_base<scheduler>(ctx), one_thread_(concurrency_hint == 1 || !BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING( @@ -100,17 +119,44 @@ scheduler::scheduler( outstanding_work_(0), stopped_(false), shutdown_(false), - concurrency_hint_(concurrency_hint) + concurrency_hint_(concurrency_hint), + thread_(0) { BOOST_ASIO_HANDLER_TRACKING_INIT; + + if (own_thread) + { + ++outstanding_work_; + boost::asio::detail::signal_blocker sb; + thread_ = new boost::asio::detail::thread(thread_function(this)); + } +} + +scheduler::~scheduler() +{ + if (thread_) + { + thread_->join(); + delete thread_; + } } void scheduler::shutdown() { mutex::scoped_lock lock(mutex_); shutdown_ = true; + if (thread_) + stop_all_threads(lock); lock.unlock(); + // Join thread to ensure task operation is returned to queue. + if (thread_) + { + thread_->join(); + delete thread_; + thread_ = 0; + } + // Destroy handler objects. while (!op_queue_.empty()) { diff --git a/boost/asio/detail/impl/select_reactor.hpp b/boost/asio/detail/impl/select_reactor.hpp index 0fbaeb9ced..c741492c6a 100644 --- a/boost/asio/detail/impl/select_reactor.hpp +++ b/boost/asio/detail/impl/select_reactor.hpp @@ -2,7 +2,7 @@ // detail/impl/select_reactor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/select_reactor.ipp b/boost/asio/detail/impl/select_reactor.ipp index 4f1f5a8303..34d3d9f031 100644 --- a/boost/asio/detail/impl/select_reactor.ipp +++ b/boost/asio/detail/impl/select_reactor.ipp @@ -2,7 +2,7 @@ // detail/impl/select_reactor.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/service_registry.hpp b/boost/asio/detail/impl/service_registry.hpp index c50614410e..e18473c8c8 100644 --- a/boost/asio/detail/impl/service_registry.hpp +++ b/boost/asio/detail/impl/service_registry.hpp @@ -2,7 +2,7 @@ // detail/impl/service_registry.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/service_registry.ipp b/boost/asio/detail/impl/service_registry.ipp index abdcd6a01a..da920fbc50 100644 --- a/boost/asio/detail/impl/service_registry.ipp +++ b/boost/asio/detail/impl/service_registry.ipp @@ -2,7 +2,7 @@ // detail/impl/service_registry.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/signal_set_service.ipp b/boost/asio/detail/impl/signal_set_service.ipp index abd83b480c..5e23702bb0 100644 --- a/boost/asio/detail/impl/signal_set_service.ipp +++ b/boost/asio/detail/impl/signal_set_service.ipp @@ -2,7 +2,7 @@ // detail/impl/signal_set_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -119,14 +119,13 @@ public: // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) -signal_set_service::signal_set_service( - boost::asio::io_context& io_context) - : service_base<signal_set_service>(io_context), - io_context_(boost::asio::use_service<io_context_impl>(io_context)), +signal_set_service::signal_set_service(execution_context& context) + : execution_context_service_base<signal_set_service>(context), + scheduler_(boost::asio::use_service<scheduler_impl>(context)), #if !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) - reactor_(boost::asio::use_service<reactor>(io_context)), + reactor_(boost::asio::use_service<reactor>(context)), #endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) @@ -170,11 +169,10 @@ void signal_set_service::shutdown() } } - io_context_.abandon_operations(ops); + scheduler_.abandon_operations(ops); } -void signal_set_service::notify_fork( - boost::asio::io_context::fork_event fork_ev) +void signal_set_service::notify_fork(execution_context::fork_event fork_ev) { #if !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ @@ -184,7 +182,7 @@ void signal_set_service::notify_fork( switch (fork_ev) { - case boost::asio::io_context::fork_prepare: + case execution_context::fork_prepare: { int read_descriptor = state->read_descriptor_; state->fork_prepared_ = true; @@ -193,7 +191,7 @@ void signal_set_service::notify_fork( reactor_.cleanup_descriptor_data(reactor_data_); } break; - case boost::asio::io_context::fork_parent: + case execution_context::fork_parent: if (state->fork_prepared_) { int read_descriptor = state->read_descriptor_; @@ -203,7 +201,7 @@ void signal_set_service::notify_fork( read_descriptor, reactor_data_, new pipe_read_op); } break; - case boost::asio::io_context::fork_child: + case execution_context::fork_child: if (state->fork_prepared_) { boost::asio::detail::signal_blocker blocker; @@ -442,7 +440,7 @@ boost::system::error_code signal_set_service::cancel( signal_set_service::implementation_type& impl, boost::system::error_code& ec) { - BOOST_ASIO_HANDLER_OPERATION((io_context_.context(), + BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "signal_set", &impl, 0, "cancel")); op_queue<operation> ops; @@ -458,7 +456,7 @@ boost::system::error_code signal_set_service::cancel( } } - io_context_.post_deferred_completions(ops); + scheduler_.post_deferred_completions(ops); ec = boost::system::error_code(); return ec; @@ -494,7 +492,7 @@ void signal_set_service::deliver_signal(int signal_number) reg = reg->next_in_table_; } - service->io_context_.post_deferred_completions(ops); + service->scheduler_.post_deferred_completions(ops); service = service->next_; } @@ -511,17 +509,17 @@ void signal_set_service::add_service(signal_set_service* service) open_descriptors(); #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) - // If an io_context object is thread-unsafe then it must be the only - // io_context used to create signal_set objects. + // If a scheduler_ object is thread-unsafe then it must be the only + // scheduler used to create signal_set objects. if (state->service_list_ != 0) { if (!BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(SCHEDULER, - service->io_context_.concurrency_hint()) + service->scheduler_.concurrency_hint()) || !BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(SCHEDULER, - state->service_list_->io_context_.concurrency_hint())) + state->service_list_->scheduler_.concurrency_hint())) { std::logic_error ex( - "Thread-unsafe io_context objects require " + "Thread-unsafe execution context objects require " "exclusive access to signal handling."); boost::asio::detail::throw_exception(ex); } @@ -640,7 +638,7 @@ void signal_set_service::close_descriptors() void signal_set_service::start_wait_op( signal_set_service::implementation_type& impl, signal_op* op) { - io_context_.work_started(); + scheduler_.work_started(); signal_state* state = get_signal_state(); static_mutex::scoped_lock lock(state->mutex_); @@ -652,7 +650,7 @@ void signal_set_service::start_wait_op( { --reg->undelivered_; op->signal_number_ = reg->signal_number_; - io_context_.post_deferred_completion(op); + scheduler_.post_deferred_completion(op); return; } diff --git a/boost/asio/detail/impl/socket_ops.ipp b/boost/asio/detail/impl/socket_ops.ipp index bb60df0a8e..7d7c31fe03 100644 --- a/boost/asio/detail/impl/socket_ops.ipp +++ b/boost/asio/detail/impl/socket_ops.ipp @@ -2,7 +2,7 @@ // detail/impl/socket_ops.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -772,7 +772,7 @@ signed_size_type recv(socket_type s, buf* bufs, size_t count, else if (ec.value() == ERROR_PORT_UNREACHABLE) ec = boost::asio::error::connection_refused; else if (ec.value() == WSAEMSGSIZE || ec.value() == ERROR_MORE_DATA) - ec.assign(0, ec.category()); + result = 0; if (result != 0) return socket_error_retval; ec = boost::system::error_code(); @@ -926,7 +926,7 @@ signed_size_type recvfrom(socket_type s, buf* bufs, size_t count, else if (ec.value() == ERROR_PORT_UNREACHABLE) ec = boost::asio::error::connection_refused; else if (ec.value() == WSAEMSGSIZE || ec.value() == ERROR_MORE_DATA) - ec.assign(0, ec.category()); + result = 0; if (result != 0) return socket_error_retval; ec = boost::system::error_code(); @@ -1503,7 +1503,8 @@ int setsockopt(socket_type s, state_type& state, int level, int optname, ec = boost::system::error_code(); #if defined(__MACH__) && defined(__APPLE__) \ - || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) + || defined(__NetBSD__) || defined(__FreeBSD__) \ + || defined(__OpenBSD__) || defined(__QNX__) // To implement portable behaviour for SO_REUSEADDR with UDP sockets we // need to also set SO_REUSEPORT on BSD-based platforms. if ((state & datagram_oriented) diff --git a/boost/asio/detail/impl/socket_select_interrupter.ipp b/boost/asio/detail/impl/socket_select_interrupter.ipp index 3d9e5289d3..e09c5fbeb0 100644 --- a/boost/asio/detail/impl/socket_select_interrupter.ipp +++ b/boost/asio/detail/impl/socket_select_interrupter.ipp @@ -2,7 +2,7 @@ // detail/impl/socket_select_interrupter.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/strand_executor_service.hpp b/boost/asio/detail/impl/strand_executor_service.hpp index 6452b949f4..67eb8361dd 100644 --- a/boost/asio/detail/impl/strand_executor_service.hpp +++ b/boost/asio/detail/impl/strand_executor_service.hpp @@ -2,7 +2,7 @@ // detail/impl/strand_executor_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/strand_executor_service.ipp b/boost/asio/detail/impl/strand_executor_service.ipp index aed4d3cf6a..60681ea2f2 100644 --- a/boost/asio/detail/impl/strand_executor_service.ipp +++ b/boost/asio/detail/impl/strand_executor_service.ipp @@ -2,7 +2,7 @@ // detail/impl/strand_executor_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/strand_service.hpp b/boost/asio/detail/impl/strand_service.hpp index d47708bb98..7e82876ea2 100644 --- a/boost/asio/detail/impl/strand_service.hpp +++ b/boost/asio/detail/impl/strand_service.hpp @@ -2,7 +2,7 @@ // detail/impl/strand_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/strand_service.ipp b/boost/asio/detail/impl/strand_service.ipp index 9926f9abf3..340f310bf6 100644 --- a/boost/asio/detail/impl/strand_service.ipp +++ b/boost/asio/detail/impl/strand_service.ipp @@ -2,7 +2,7 @@ // detail/impl/strand_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/throw_error.ipp b/boost/asio/detail/impl/throw_error.ipp index ffcacf47ae..9483bd0f59 100644 --- a/boost/asio/detail/impl/throw_error.ipp +++ b/boost/asio/detail/impl/throw_error.ipp @@ -2,7 +2,7 @@ // detail/impl/throw_error.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/timer_queue_ptime.ipp b/boost/asio/detail/impl/timer_queue_ptime.ipp index 8a6d5af815..2566c9c2ca 100644 --- a/boost/asio/detail/impl/timer_queue_ptime.ipp +++ b/boost/asio/detail/impl/timer_queue_ptime.ipp @@ -2,7 +2,7 @@ // detail/impl/timer_queue_ptime.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/timer_queue_set.ipp b/boost/asio/detail/impl/timer_queue_set.ipp index 71f83216aa..b738142f28 100644 --- a/boost/asio/detail/impl/timer_queue_set.ipp +++ b/boost/asio/detail/impl/timer_queue_set.ipp @@ -2,7 +2,7 @@ // detail/impl/timer_queue_set.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/win_event.ipp b/boost/asio/detail/impl/win_event.ipp index 3e7dfdcf21..c6e1e3582f 100644 --- a/boost/asio/detail/impl/win_event.ipp +++ b/boost/asio/detail/impl/win_event.ipp @@ -2,7 +2,7 @@ // detail/win_event.ipp // ~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/win_iocp_handle_service.ipp b/boost/asio/detail/impl/win_iocp_handle_service.ipp index 0cd7dd1719..1256c358ac 100644 --- a/boost/asio/detail/impl/win_iocp_handle_service.ipp +++ b/boost/asio/detail/impl/win_iocp_handle_service.ipp @@ -2,7 +2,7 @@ // detail/impl/win_iocp_handle_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -66,10 +66,9 @@ public: } }; -win_iocp_handle_service::win_iocp_handle_service( - boost::asio::io_context& io_context) - : service_base<win_iocp_handle_service>(io_context), - iocp_service_(boost::asio::use_service<win_iocp_io_context>(io_context)), +win_iocp_handle_service::win_iocp_handle_service(execution_context& context) + : execution_context_service_base<win_iocp_handle_service>(context), + iocp_service_(boost::asio::use_service<win_iocp_io_context>(context)), mutex_(), impl_list_(0) { diff --git a/boost/asio/detail/impl/win_iocp_io_context.hpp b/boost/asio/detail/impl/win_iocp_io_context.hpp index 771c1f3c3a..830a07dcd9 100644 --- a/boost/asio/detail/impl/win_iocp_io_context.hpp +++ b/boost/asio/detail/impl/win_iocp_io_context.hpp @@ -2,7 +2,7 @@ // detail/impl/win_iocp_io_context.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/win_iocp_io_context.ipp b/boost/asio/detail/impl/win_iocp_io_context.ipp index 87637f0b5c..5bdc540972 100644 --- a/boost/asio/detail/impl/win_iocp_io_context.ipp +++ b/boost/asio/detail/impl/win_iocp_io_context.ipp @@ -2,7 +2,7 @@ // detail/impl/win_iocp_io_context.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -24,6 +24,7 @@ #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_invoke_helpers.hpp> #include <boost/asio/detail/limits.hpp> +#include <boost/asio/detail/thread.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/detail/win_iocp_io_context.hpp> @@ -33,6 +34,22 @@ namespace boost { namespace asio { namespace detail { +struct win_iocp_io_context::thread_function +{ + explicit thread_function(win_iocp_io_context* s) + : this_(s) + { + } + + void operator()() + { + boost::system::error_code ec; + this_->run(ec); + } + + win_iocp_io_context* this_; +}; + struct win_iocp_io_context::work_finished_on_block_exit { ~work_finished_on_block_exit() @@ -63,7 +80,7 @@ struct win_iocp_io_context::timer_thread_function }; win_iocp_io_context::win_iocp_io_context( - boost::asio::execution_context& ctx, int concurrency_hint) + boost::asio::execution_context& ctx, int concurrency_hint, bool own_thread) : execution_context_service_base<win_iocp_io_context>(ctx), iocp_(), outstanding_work_(0), @@ -85,6 +102,21 @@ win_iocp_io_context::win_iocp_io_context( boost::asio::error::get_system_category()); boost::asio::detail::throw_error(ec, "iocp"); } + + if (own_thread) + { + ::InterlockedIncrement(&outstanding_work_); + thread_.reset(new boost::asio::detail::thread(thread_function(this))); + } +} + +win_iocp_io_context::~win_iocp_io_context() +{ + if (thread_.get()) + { + thread_->join(); + thread_.reset(); + } } void win_iocp_io_context::shutdown() @@ -98,6 +130,13 @@ void win_iocp_io_context::shutdown() ::SetWaitableTimer(waitable_timer_.handle, &timeout, 1, 0, 0, FALSE); } + if (thread_.get()) + { + thread_->join(); + thread_.reset(); + ::InterlockedDecrement(&outstanding_work_); + } + while (::InterlockedExchangeAdd(&outstanding_work_, 0) > 0) { op_queue<win_iocp_operation> ops; diff --git a/boost/asio/detail/impl/win_iocp_serial_port_service.ipp b/boost/asio/detail/impl/win_iocp_serial_port_service.ipp index 7dbf9353ee..4e30b0f678 100644 --- a/boost/asio/detail/impl/win_iocp_serial_port_service.ipp +++ b/boost/asio/detail/impl/win_iocp_serial_port_service.ipp @@ -2,7 +2,7 @@ // detail/impl/win_iocp_serial_port_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -30,9 +30,9 @@ namespace asio { namespace detail { win_iocp_serial_port_service::win_iocp_serial_port_service( - boost::asio::io_context& io_context) - : service_base<win_iocp_serial_port_service>(io_context), - handle_service_(io_context) + execution_context& context) + : execution_context_service_base<win_iocp_serial_port_service>(context), + handle_service_(context) { } diff --git a/boost/asio/detail/impl/win_iocp_socket_service_base.ipp b/boost/asio/detail/impl/win_iocp_socket_service_base.ipp index 3b7e7066f5..f95c74ff58 100644 --- a/boost/asio/detail/impl/win_iocp_socket_service_base.ipp +++ b/boost/asio/detail/impl/win_iocp_socket_service_base.ipp @@ -2,7 +2,7 @@ // detail/impl/win_iocp_socket_service_base.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -28,9 +28,9 @@ namespace asio { namespace detail { win_iocp_socket_service_base::win_iocp_socket_service_base( - boost::asio::io_context& io_context) - : io_context_(io_context), - iocp_service_(use_service<win_iocp_io_context>(io_context)), + execution_context& context) + : context_(context), + iocp_service_(use_service<win_iocp_io_context>(context)), reactor_(0), connect_ex_(0), nt_set_info_(0), @@ -708,7 +708,7 @@ select_reactor& win_iocp_socket_service_base::get_reactor() reinterpret_cast<void**>(&reactor_), 0, 0)); if (!r) { - r = &(use_service<select_reactor>(io_context_)); + r = &(use_service<select_reactor>(context_)); interlocked_exchange_pointer(reinterpret_cast<void**>(&reactor_), r); } return *r; diff --git a/boost/asio/detail/impl/win_mutex.ipp b/boost/asio/detail/impl/win_mutex.ipp index 12922263f2..809d40f159 100644 --- a/boost/asio/detail/impl/win_mutex.ipp +++ b/boost/asio/detail/impl/win_mutex.ipp @@ -2,7 +2,7 @@ // detail/impl/win_mutex.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/win_object_handle_service.ipp b/boost/asio/detail/impl/win_object_handle_service.ipp index db56f722f2..f356a00613 100644 --- a/boost/asio/detail/impl/win_object_handle_service.ipp +++ b/boost/asio/detail/impl/win_object_handle_service.ipp @@ -2,7 +2,7 @@ // detail/impl/win_object_handle_service.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2011 Boris Schaeling (boris@highscore.de) // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -28,10 +28,9 @@ namespace boost { namespace asio { namespace detail { -win_object_handle_service::win_object_handle_service( - boost::asio::io_context& io_context) - : service_base<win_object_handle_service>(io_context), - io_context_(boost::asio::use_service<io_context_impl>(io_context)), +win_object_handle_service::win_object_handle_service(execution_context& context) + : execution_context_service_base<win_object_handle_service>(context), + scheduler_(boost::asio::use_service<scheduler_impl>(context)), mutex_(), impl_list_(0), shutdown_(false) @@ -53,7 +52,7 @@ void win_object_handle_service::shutdown() lock.unlock(); - io_context_.abandon_operations(ops); + scheduler_.abandon_operations(ops); } void win_object_handle_service::construct( @@ -179,7 +178,7 @@ void win_object_handle_service::destroy( if (is_open(impl)) { - BOOST_ASIO_HANDLER_OPERATION((io_context_.context(), "object_handle", + BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "object_handle", &impl, reinterpret_cast<uintmax_t>(impl.wait_handle_), "close")); HANDLE wait_handle = impl.wait_handle_; @@ -204,7 +203,7 @@ void win_object_handle_service::destroy( ::CloseHandle(impl.handle_); impl.handle_ = INVALID_HANDLE_VALUE; - io_context_.post_deferred_completions(ops); + scheduler_.post_deferred_completions(ops); } } @@ -229,7 +228,7 @@ boost::system::error_code win_object_handle_service::close( { if (is_open(impl)) { - BOOST_ASIO_HANDLER_OPERATION((io_context_.context(), "object_handle", + BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "object_handle", &impl, reinterpret_cast<uintmax_t>(impl.wait_handle_), "close")); mutex::scoped_lock lock(mutex_); @@ -265,7 +264,7 @@ boost::system::error_code win_object_handle_service::close( boost::asio::error::get_system_category()); } - io_context_.post_deferred_completions(completed_ops); + scheduler_.post_deferred_completions(completed_ops); } else { @@ -281,7 +280,7 @@ boost::system::error_code win_object_handle_service::cancel( { if (is_open(impl)) { - BOOST_ASIO_HANDLER_OPERATION((io_context_.context(), "object_handle", + BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "object_handle", &impl, reinterpret_cast<uintmax_t>(impl.wait_handle_), "cancel")); mutex::scoped_lock lock(mutex_); @@ -307,7 +306,7 @@ boost::system::error_code win_object_handle_service::cancel( ec = boost::system::error_code(); - io_context_.post_deferred_completions(completed_ops); + scheduler_.post_deferred_completions(completed_ops); } else { @@ -341,7 +340,7 @@ void win_object_handle_service::wait( void win_object_handle_service::start_wait_op( win_object_handle_service::implementation_type& impl, wait_op* op) { - io_context_.work_started(); + scheduler_.work_started(); if (is_open(impl)) { @@ -359,13 +358,13 @@ void win_object_handle_service::start_wait_op( else { lock.unlock(); - io_context_.post_deferred_completion(op); + scheduler_.post_deferred_completion(op); } } else { op->ec_ = boost::asio::error::bad_descriptor; - io_context_.post_deferred_completion(op); + scheduler_.post_deferred_completion(op); } } @@ -392,7 +391,7 @@ void win_object_handle_service::register_wait_callback( } lock.unlock(); - io_context_.post_deferred_completions(completed_ops); + scheduler_.post_deferred_completions(completed_ops); } } @@ -434,9 +433,9 @@ void win_object_handle_service::wait_callback(PVOID param, BOOLEAN) } } - io_context_impl& ioc = impl->owner_->io_context_; + scheduler_impl& sched = impl->owner_->scheduler_; lock.unlock(); - ioc.post_deferred_completions(completed_ops); + sched.post_deferred_completions(completed_ops); } } diff --git a/boost/asio/detail/impl/win_static_mutex.ipp b/boost/asio/detail/impl/win_static_mutex.ipp index 10e8622e37..ae53dbe105 100644 --- a/boost/asio/detail/impl/win_static_mutex.ipp +++ b/boost/asio/detail/impl/win_static_mutex.ipp @@ -2,7 +2,7 @@ // detail/impl/win_static_mutex.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/win_thread.ipp b/boost/asio/detail/impl/win_thread.ipp index 710c9b9f9b..13faa0753e 100644 --- a/boost/asio/detail/impl/win_thread.ipp +++ b/boost/asio/detail/impl/win_thread.ipp @@ -2,7 +2,7 @@ // detail/impl/win_thread.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/win_tss_ptr.ipp b/boost/asio/detail/impl/win_tss_ptr.ipp index 755d020703..8c6c5c60d7 100644 --- a/boost/asio/detail/impl/win_tss_ptr.ipp +++ b/boost/asio/detail/impl/win_tss_ptr.ipp @@ -2,7 +2,7 @@ // detail/impl/win_tss_ptr.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/asio/detail/impl/winrt_ssocket_service_base.ipp b/boost/asio/detail/impl/winrt_ssocket_service_base.ipp index e6254aed93..1728281091 100644 --- a/boost/asio/detail/impl/winrt_ssocket_service_base.ipp +++ b/boost/asio/detail/impl/winrt_ssocket_service_base.ipp @@ -2,7 +2,7 @@ // detail/impl/winrt_ssocket_service_base.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -31,9 +31,9 @@ namespace asio { namespace detail { winrt_ssocket_service_base::winrt_ssocket_service_base( - boost::asio::io_context& io_context) - : io_context_(use_service<io_context_impl>(io_context)), - async_manager_(use_service<winrt_async_manager>(io_context)), + execution_context& context) + : scheduler_(use_service<scheduler_impl>(context)), + async_manager_(use_service<winrt_async_manager>(context)), mutex_(), impl_list_(0) { @@ -399,7 +399,7 @@ void winrt_ssocket_service_base::start_connect_op( if (!is_open(impl)) { op->ec_ = boost::asio::error::bad_descriptor; - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } @@ -428,7 +428,7 @@ void winrt_ssocket_service_base::start_connect_op( if (op->ec_) { - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } @@ -443,7 +443,7 @@ void winrt_ssocket_service_base::start_connect_op( { op->ec_ = boost::system::error_code( e->HResult, boost::system::system_category()); - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); } } @@ -494,14 +494,14 @@ void winrt_ssocket_service_base::start_send_op( if (flags) { op->ec_ = boost::asio::error::operation_not_supported; - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } if (!is_open(impl)) { op->ec_ = boost::asio::error::bad_descriptor; - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } @@ -512,7 +512,7 @@ void winrt_ssocket_service_base::start_send_op( if (bufs.all_empty()) { - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } @@ -523,7 +523,7 @@ void winrt_ssocket_service_base::start_send_op( { op->ec_ = boost::system::error_code(e->HResult, boost::system::system_category()); - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); } } @@ -585,14 +585,14 @@ void winrt_ssocket_service_base::start_receive_op( if (flags) { op->ec_ = boost::asio::error::operation_not_supported; - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } if (!is_open(impl)) { op->ec_ = boost::asio::error::bad_descriptor; - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } @@ -603,7 +603,7 @@ void winrt_ssocket_service_base::start_receive_op( if (bufs.all_empty()) { - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); return; } @@ -616,7 +616,7 @@ void winrt_ssocket_service_base::start_receive_op( { op->ec_ = boost::system::error_code(e->HResult, boost::system::system_category()); - io_context_.post_immediate_completion(op, is_continuation); + scheduler_.post_immediate_completion(op, is_continuation); } } diff --git a/boost/asio/detail/impl/winrt_timer_scheduler.hpp b/boost/asio/detail/impl/winrt_timer_scheduler.hpp index a475f66640..89ac7a123c 100644 --- a/boost/asio/detail/impl/winrt_timer_scheduler.hpp +++ b/boost/asio/detail/impl/winrt_timer_scheduler.hpp @@ -2,7 +2,7 @@ // detail/impl/winrt_timer_scheduler.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -47,12 +47,12 @@ void winrt_timer_scheduler::schedule_timer(timer_queue<Time_Traits>& queue, if (shutdown_) { - io_context_.post_immediate_completion(op, false); + scheduler_.post_immediate_completion(op, false); return; } bool earliest = queue.enqueue_timer(time, timer, op); - io_context_.work_started(); + scheduler_.work_started(); if (earliest) event_.signal(lock); } @@ -66,7 +66,7 @@ std::size_t winrt_timer_scheduler::cancel_timer(timer_queue<Time_Traits>& queue, op_queue<operation> ops; std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); lock.unlock(); - io_context_.post_deferred_completions(ops); + scheduler_.post_deferred_completions(ops); return n; } diff --git a/boost/asio/detail/impl/winrt_timer_scheduler.ipp b/boost/asio/detail/impl/winrt_timer_scheduler.ipp index c8b77349cd..48cb29c42e 100644 --- a/boost/asio/detail/impl/winrt_timer_scheduler.ipp +++ b/boost/asio/detail/impl/winrt_timer_scheduler.ipp @@ -2,7 +2,7 @@ // detail/impl/winrt_timer_scheduler.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -28,10 +28,9 @@ namespace boost { namespace asio { namespace detail { -winrt_timer_scheduler::winrt_timer_scheduler( - boost::asio::io_context& io_context) - : boost::asio::detail::service_base<winrt_timer_scheduler>(io_context), - io_context_(use_service<io_context_impl>(io_context)), +winrt_timer_scheduler::winrt_timer_scheduler(execution_context& context) + : execution_context_service_base<winrt_timer_scheduler>(context), + scheduler_(use_service<scheduler_impl>(context)), mutex_(), event_(), timer_queues_(), @@ -65,10 +64,10 @@ void winrt_timer_scheduler::shutdown() op_queue<operation> ops; timer_queues_.get_all_timers(ops); - io_context_.abandon_operations(ops); + scheduler_.abandon_operations(ops); } -void winrt_timer_scheduler::notify_fork(boost::asio::io_context::fork_event) +void winrt_timer_scheduler::notify_fork(execution_context::fork_event) { } @@ -90,7 +89,7 @@ void winrt_timer_scheduler::run_thread() if (!ops.empty()) { lock.unlock(); - io_context_.post_deferred_completions(ops); + scheduler_.post_deferred_completions(ops); lock.lock(); } } diff --git a/boost/asio/detail/impl/winsock_init.ipp b/boost/asio/detail/impl/winsock_init.ipp index 5d31a03b06..85b50df5d0 100644 --- a/boost/asio/detail/impl/winsock_init.ipp +++ b/boost/asio/detail/impl/winsock_init.ipp @@ -2,7 +2,7 @@ // detail/impl/winsock_init.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |