#ifndef BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP #define BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP #include #include #include namespace boost { namespace beast { namespace detail { template struct select_work_guard; template using select_work_guard_t = typename select_work_guard::type; #if !defined(BOOST_ASIO_NO_TS_EXECUTORS) template struct select_work_guard < Executor, typename std::enable_if < net::is_executor::value >::type > { using type = net::executor_work_guard; }; #endif template struct execution_work_guard { using executor_type = decltype( net::prefer(std::declval(), net::execution::outstanding_work.tracked)); execution_work_guard(Executor const& exec) : ex_(net::prefer(exec, net::execution::outstanding_work.tracked)) { } executor_type get_executor() const noexcept { BOOST_ASSERT(ex_.has_value()); return *ex_; } void reset() noexcept { ex_.reset(); } private: boost::optional ex_; }; template struct select_work_guard < Executor, typename std::enable_if < net::execution::is_executor::value #if defined(BOOST_ASIO_NO_TS_EXECUTORS) || net::is_executor::value #else && !net::is_executor::value #endif >::type > { using type = execution_work_guard; }; template select_work_guard_t make_work_guard(Executor const& exec) noexcept { return select_work_guard_t(exec); } } } } #endif // BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP