diff options
Diffstat (limited to '3rdparty/asio/include/asio/impl/system_executor.hpp')
-rw-r--r-- | 3rdparty/asio/include/asio/impl/system_executor.hpp | 160 |
1 files changed, 120 insertions, 40 deletions
diff --git a/3rdparty/asio/include/asio/impl/system_executor.hpp b/3rdparty/asio/include/asio/impl/system_executor.hpp index 12ca9b958d4..099b2d63ef2 100644 --- a/3rdparty/asio/include/asio/impl/system_executor.hpp +++ b/3rdparty/asio/include/asio/impl/system_executor.hpp @@ -2,7 +2,7 @@ // impl/system_executor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 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) @@ -17,46 +17,133 @@ #include "asio/detail/executor_op.hpp" #include "asio/detail/global.hpp" -#include "asio/detail/recycling_allocator.hpp" #include "asio/detail/type_traits.hpp" -#include "asio/execution_context.hpp" +#include "asio/system_context.hpp" #include "asio/detail/push_options.hpp" namespace asio { -inline execution_context& system_executor::context() const ASIO_NOEXCEPT +template <typename Blocking, typename Relationship, typename Allocator> +inline system_context& +basic_system_executor<Blocking, Relationship, Allocator>::query( + execution::context_t) noexcept { - return detail::global<context_impl>(); + return detail::global<system_context>(); } -template <typename Function, typename Allocator> -void system_executor::dispatch( - ASIO_MOVE_ARG(Function) f, const Allocator&) const +template <typename Blocking, typename Relationship, typename Allocator> +inline std::size_t +basic_system_executor<Blocking, Relationship, Allocator>::query( + execution::occupancy_t) const noexcept { - typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f)); - asio_handler_invoke_helpers::invoke(tmp, tmp); + return detail::global<system_context>().num_threads_; } -template <typename Function, typename Allocator> -void system_executor::post( - ASIO_MOVE_ARG(Function) f, const Allocator& a) const +template <typename Blocking, typename Relationship, typename Allocator> +template <typename Function> +inline void +basic_system_executor<Blocking, Relationship, Allocator>::do_execute( + Function&& f, execution::blocking_t::possibly_t) const { - context_impl& ctx = detail::global<context_impl>(); + // Obtain a non-const instance of the function. + detail::non_const_lvalue<Function> f2(f); + +#if !defined(ASIO_NO_EXCEPTIONS) + try + { +#endif// !defined(ASIO_NO_EXCEPTIONS) + detail::fenced_block b(detail::fenced_block::full); + static_cast<decay_t<Function>&&>(f2.value)(); +#if !defined(ASIO_NO_EXCEPTIONS) + } + catch (...) + { + std::terminate(); + } +#endif// !defined(ASIO_NO_EXCEPTIONS) +} + +template <typename Blocking, typename Relationship, typename Allocator> +template <typename Function> +inline void +basic_system_executor<Blocking, Relationship, Allocator>::do_execute( + Function&& f, execution::blocking_t::always_t) const +{ + // Obtain a non-const instance of the function. + detail::non_const_lvalue<Function> f2(f); + +#if !defined(ASIO_NO_EXCEPTIONS) + try + { +#endif// !defined(ASIO_NO_EXCEPTIONS) + detail::fenced_block b(detail::fenced_block::full); + static_cast<decay_t<Function>&&>(f2.value)(); +#if !defined(ASIO_NO_EXCEPTIONS) + } + catch (...) + { + std::terminate(); + } +#endif// !defined(ASIO_NO_EXCEPTIONS) +} + +template <typename Blocking, typename Relationship, typename Allocator> +template <typename Function> +void basic_system_executor<Blocking, Relationship, Allocator>::do_execute( + Function&& f, execution::blocking_t::never_t) const +{ + system_context& ctx = detail::global<system_context>(); + + // Allocate and construct an operation to wrap the function. + typedef detail::executor_op<decay_t<Function>, Allocator> op; + typename op::ptr p = { detail::addressof(allocator_), + op::ptr::allocate(allocator_), 0 }; + p.p = new (p.v) op(static_cast<Function&&>(f), allocator_); + + if (is_same<Relationship, execution::relationship_t::continuation_t>::value) + { + ASIO_HANDLER_CREATION((ctx, *p.p, + "system_executor", &ctx, 0, "execute(blk=never,rel=cont)")); + } + else + { + ASIO_HANDLER_CREATION((ctx, *p.p, + "system_executor", &ctx, 0, "execute(blk=never,rel=fork)")); + } + + ctx.scheduler_.post_immediate_completion(p.p, + is_same<Relationship, execution::relationship_t::continuation_t>::value); + p.v = p.p = 0; +} - // Make a local, non-const copy of the function. - typedef typename decay<Function>::type function_type; - function_type tmp(ASIO_MOVE_CAST(Function)(f)); +#if !defined(ASIO_NO_TS_EXECUTORS) +template <typename Blocking, typename Relationship, typename Allocator> +inline system_context& basic_system_executor< + Blocking, Relationship, Allocator>::context() const noexcept +{ + return detail::global<system_context>(); +} - // Construct an allocator to be used for the operation. - typedef typename detail::get_recycling_allocator<Allocator>::type alloc_type; - alloc_type allocator(detail::get_recycling_allocator<Allocator>::get(a)); +template <typename Blocking, typename Relationship, typename Allocator> +template <typename Function, typename OtherAllocator> +void basic_system_executor<Blocking, Relationship, Allocator>::dispatch( + Function&& f, const OtherAllocator&) const +{ + decay_t<Function>(static_cast<Function&&>(f))(); +} + +template <typename Blocking, typename Relationship, typename Allocator> +template <typename Function, typename OtherAllocator> +void basic_system_executor<Blocking, Relationship, Allocator>::post( + Function&& f, const OtherAllocator& a) const +{ + system_context& ctx = detail::global<system_context>(); // Allocate and construct an operation to wrap the function. - typedef detail::executor_op<function_type, alloc_type> op; - typename op::ptr p = { allocator, 0, 0 }; - p.v = p.a.allocate(1); - p.p = new (p.v) op(tmp, allocator); + typedef detail::executor_op<decay_t<Function>, OtherAllocator> op; + typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 }; + p.p = new (p.v) op(static_cast<Function&&>(f), a); ASIO_HANDLER_CREATION((ctx, *p.p, "system_executor", &this->context(), 0, "post")); @@ -65,25 +152,17 @@ void system_executor::post( p.v = p.p = 0; } -template <typename Function, typename Allocator> -void system_executor::defer( - ASIO_MOVE_ARG(Function) f, const Allocator& a) const +template <typename Blocking, typename Relationship, typename Allocator> +template <typename Function, typename OtherAllocator> +void basic_system_executor<Blocking, Relationship, Allocator>::defer( + Function&& f, const OtherAllocator& a) const { - context_impl& ctx = detail::global<context_impl>(); - - // Make a local, non-const copy of the function. - typedef typename decay<Function>::type function_type; - function_type tmp(ASIO_MOVE_CAST(Function)(f)); - - // Construct an allocator to be used for the operation. - typedef typename detail::get_recycling_allocator<Allocator>::type alloc_type; - alloc_type allocator(detail::get_recycling_allocator<Allocator>::get(a)); + system_context& ctx = detail::global<system_context>(); // Allocate and construct an operation to wrap the function. - typedef detail::executor_op<function_type, alloc_type> op; - typename op::ptr p = { allocator, 0, 0 }; - p.v = p.a.allocate(1); - p.p = new (p.v) op(tmp, allocator); + typedef detail::executor_op<decay_t<Function>, OtherAllocator> op; + typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 }; + p.p = new (p.v) op(static_cast<Function&&>(f), a); ASIO_HANDLER_CREATION((ctx, *p.p, "system_executor", &this->context(), 0, "defer")); @@ -91,6 +170,7 @@ void system_executor::defer( ctx.scheduler_.post_immediate_completion(p.p, true); p.v = p.p = 0; } +#endif // !defined(ASIO_NO_TS_EXECUTORS) } // namespace asio |