Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:25

0001 //
0002 // Copyright (c) 2020 Richard Hodges (hodges.r@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP
0011 #define BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP
0012 
0013 #include <boost/asio/executor_work_guard.hpp>
0014 #include <boost/asio/execution.hpp>
0015 #include <boost/optional.hpp>
0016 
0017 namespace boost {
0018 namespace beast {
0019 namespace detail {
0020 
0021 template<class Executor, class Enable = void>
0022 struct select_work_guard;
0023 
0024 template<class Executor>
0025 using select_work_guard_t = typename
0026     select_work_guard<Executor>::type;
0027 
0028 #if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
0029 template<class Executor>
0030 struct select_work_guard
0031 <
0032     Executor,
0033     typename std::enable_if
0034     <
0035         net::is_executor<Executor>::value
0036     >::type
0037 >
0038 {
0039     using type = net::executor_work_guard<Executor>;
0040 };
0041 #endif
0042 
0043 template<class Executor>
0044 struct execution_work_guard
0045 {
0046     using executor_type = typename std::decay<decltype(
0047          net::prefer(std::declval<Executor const&>(),
0048             net::execution::outstanding_work.tracked))>::type;
0049 
0050     execution_work_guard(Executor const& exec)
0051     : ex_(net::prefer(exec, net::execution::outstanding_work.tracked))
0052     {
0053 
0054     }
0055 
0056     executor_type
0057     get_executor() const noexcept
0058     {
0059         BOOST_ASSERT(ex_.has_value());
0060         return *ex_;
0061     }
0062 
0063     void reset() noexcept
0064     {
0065         ex_.reset();
0066     }
0067 
0068 private:
0069 
0070     boost::optional<executor_type> ex_;
0071 };
0072 
0073 template<class Executor>
0074 struct select_work_guard
0075 <
0076     Executor,
0077     typename std::enable_if
0078     <
0079         net::execution::is_executor<Executor>::value
0080 #if defined(BOOST_ASIO_NO_TS_EXECUTORS)
0081         || net::is_executor<Executor>::value
0082 #else
0083         && !net::is_executor<Executor>::value
0084 #endif
0085     >::type
0086 >
0087 {
0088     using type = execution_work_guard<Executor>;
0089 };
0090 
0091 template<class Executor>
0092 select_work_guard_t<Executor>
0093 make_work_guard(Executor const& exec) noexcept
0094 {
0095     return select_work_guard_t<Executor>(exec);
0096 }
0097 
0098 }
0099 }
0100 }
0101 
0102 #endif // BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP