// // detail/composed_work.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #ifndef ASIO_DETAIL_COMPOSED_WORK_HPP #define ASIO_DETAIL_COMPOSED_WORK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" #include "asio/detail/type_traits.hpp" #include "asio/execution/executor.hpp" #include "asio/execution/outstanding_work.hpp" #include "asio/executor_work_guard.hpp" #include "asio/is_executor.hpp" #include "asio/system_executor.hpp" #include "asio/detail/push_options.hpp" namespace asio { namespace detail { template class composed_work_guard { public: typedef decay_t< prefer_result_t > executor_type; composed_work_guard(const Executor& ex) : executor_(asio::prefer(ex, execution::outstanding_work.tracked)) { } void reset() { } executor_type get_executor() const noexcept { return executor_; } private: executor_type executor_; }; template <> struct composed_work_guard { public: typedef system_executor executor_type; composed_work_guard(const system_executor&) { } void reset() { } executor_type get_executor() const noexcept { return system_executor(); } }; #if !defined(ASIO_NO_TS_EXECUTORS) template struct composed_work_guard::value > > : executor_work_guard { composed_work_guard(const Executor& ex) : executor_work_guard(ex) { } }; #endif // !defined(ASIO_NO_TS_EXECUTORS) template struct composed_io_executors; template <> struct composed_io_executors { composed_io_executors() noexcept : head_(system_executor()) { } typedef system_executor head_type; system_executor head_; }; inline composed_io_executors make_composed_io_executors() { return composed_io_executors(); } template struct composed_io_executors { explicit composed_io_executors(const Head& ex) noexcept : head_(ex) { } typedef Head head_type; Head head_; }; template inline composed_io_executors make_composed_io_executors(const Head& head) { return composed_io_executors(head); } template struct composed_io_executors { explicit composed_io_executors(const Head& head, const Tail&... tail) noexcept : head_(head), tail_(tail...) { } void reset() { head_.reset(); tail_.reset(); } typedef Head head_type; Head head_; composed_io_executors tail_; }; template inline composed_io_executors make_composed_io_executors(const Head& head, const Tail&... tail) { return composed_io_executors(head, tail...); } template struct composed_work; template <> struct composed_work { typedef composed_io_executors executors_type; composed_work(const executors_type&) noexcept : head_(system_executor()) { } void reset() { head_.reset(); } typedef system_executor head_type; composed_work_guard head_; }; template struct composed_work { typedef composed_io_executors executors_type; explicit composed_work(const executors_type& ex) noexcept : head_(ex.head_) { } void reset() { head_.reset(); } typedef Head head_type; composed_work_guard head_; }; template struct composed_work { typedef composed_io_executors executors_type; explicit composed_work(const executors_type& ex) noexcept : head_(ex.head_), tail_(ex.tail_) { } void reset() { head_.reset(); tail_.reset(); } typedef Head head_type; composed_work_guard head_; composed_work tail_; }; template inline typename IoObject::executor_type get_composed_io_executor(IoObject& io_object, enable_if_t< !is_executor::value >* = 0, enable_if_t< !execution::is_executor::value >* = 0) { return io_object.get_executor(); } template inline const Executor& get_composed_io_executor(const Executor& ex, enable_if_t< is_executor::value || execution::is_executor::value >* = 0) { return ex; } } // namespace detail } // namespace asio #include "asio/detail/pop_options.hpp" #endif // ASIO_DETAIL_COMPOSED_WORK_HPP