Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:37

0001 //
0002 // detail/composed_work.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_COMPOSED_WORK_HPP
0012 #define BOOST_ASIO_DETAIL_COMPOSED_WORK_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/type_traits.hpp>
0020 #include <boost/asio/execution/executor.hpp>
0021 #include <boost/asio/execution/outstanding_work.hpp>
0022 #include <boost/asio/executor_work_guard.hpp>
0023 #include <boost/asio/is_executor.hpp>
0024 #include <boost/asio/system_executor.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031 
0032 template <typename Executor, typename = void>
0033 class composed_work_guard
0034 {
0035 public:
0036   typedef decay_t<
0037       prefer_result_t<Executor, execution::outstanding_work_t::tracked_t>
0038     > executor_type;
0039 
0040   composed_work_guard(const Executor& ex)
0041     : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked))
0042   {
0043   }
0044 
0045   void reset()
0046   {
0047   }
0048 
0049   executor_type get_executor() const noexcept
0050   {
0051     return executor_;
0052   }
0053 
0054 private:
0055   executor_type executor_;
0056 };
0057 
0058 template <>
0059 struct composed_work_guard<system_executor>
0060 {
0061 public:
0062   typedef system_executor executor_type;
0063 
0064   composed_work_guard(const system_executor&)
0065   {
0066   }
0067 
0068   void reset()
0069   {
0070   }
0071 
0072   executor_type get_executor() const noexcept
0073   {
0074     return system_executor();
0075   }
0076 };
0077 
0078 #if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
0079 
0080 template <typename Executor>
0081 struct composed_work_guard<Executor,
0082     enable_if_t<
0083       !execution::is_executor<Executor>::value
0084     >
0085   > : executor_work_guard<Executor>
0086 {
0087   composed_work_guard(const Executor& ex)
0088     : executor_work_guard<Executor>(ex)
0089   {
0090   }
0091 };
0092 
0093 #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
0094 
0095 template <typename>
0096 struct composed_io_executors;
0097 
0098 template <>
0099 struct composed_io_executors<void()>
0100 {
0101   composed_io_executors() noexcept
0102     : head_(system_executor())
0103   {
0104   }
0105 
0106   typedef system_executor head_type;
0107   system_executor head_;
0108 };
0109 
0110 inline composed_io_executors<void()> make_composed_io_executors()
0111 {
0112   return composed_io_executors<void()>();
0113 }
0114 
0115 template <typename Head>
0116 struct composed_io_executors<void(Head)>
0117 {
0118   explicit composed_io_executors(const Head& ex) noexcept
0119     : head_(ex)
0120   {
0121   }
0122 
0123   typedef Head head_type;
0124   Head head_;
0125 };
0126 
0127 template <typename Head>
0128 inline composed_io_executors<void(Head)>
0129 make_composed_io_executors(const Head& head)
0130 {
0131   return composed_io_executors<void(Head)>(head);
0132 }
0133 
0134 template <typename Head, typename... Tail>
0135 struct composed_io_executors<void(Head, Tail...)>
0136 {
0137   explicit composed_io_executors(const Head& head,
0138       const Tail&... tail) noexcept
0139     : head_(head),
0140       tail_(tail...)
0141   {
0142   }
0143 
0144   void reset()
0145   {
0146     head_.reset();
0147     tail_.reset();
0148   }
0149 
0150   typedef Head head_type;
0151   Head head_;
0152   composed_io_executors<void(Tail...)> tail_;
0153 };
0154 
0155 template <typename Head, typename... Tail>
0156 inline composed_io_executors<void(Head, Tail...)>
0157 make_composed_io_executors(const Head& head, const Tail&... tail)
0158 {
0159   return composed_io_executors<void(Head, Tail...)>(head, tail...);
0160 }
0161 
0162 template <typename>
0163 struct composed_work;
0164 
0165 template <>
0166 struct composed_work<void()>
0167 {
0168   typedef composed_io_executors<void()> executors_type;
0169 
0170   composed_work(const executors_type&) noexcept
0171     : head_(system_executor())
0172   {
0173   }
0174 
0175   void reset()
0176   {
0177     head_.reset();
0178   }
0179 
0180   typedef system_executor head_type;
0181   composed_work_guard<system_executor> head_;
0182 };
0183 
0184 template <typename Head>
0185 struct composed_work<void(Head)>
0186 {
0187   typedef composed_io_executors<void(Head)> executors_type;
0188 
0189   explicit composed_work(const executors_type& ex) noexcept
0190     : head_(ex.head_)
0191   {
0192   }
0193 
0194   void reset()
0195   {
0196     head_.reset();
0197   }
0198 
0199   typedef Head head_type;
0200   composed_work_guard<Head> head_;
0201 };
0202 
0203 template <typename Head, typename... Tail>
0204 struct composed_work<void(Head, Tail...)>
0205 {
0206   typedef composed_io_executors<void(Head, Tail...)> executors_type;
0207 
0208   explicit composed_work(const executors_type& ex) noexcept
0209     : head_(ex.head_),
0210       tail_(ex.tail_)
0211   {
0212   }
0213 
0214   void reset()
0215   {
0216     head_.reset();
0217     tail_.reset();
0218   }
0219 
0220   typedef Head head_type;
0221   composed_work_guard<Head> head_;
0222   composed_work<void(Tail...)> tail_;
0223 };
0224 
0225 template <typename IoObject>
0226 inline typename IoObject::executor_type
0227 get_composed_io_executor(IoObject& io_object,
0228     enable_if_t<
0229       !is_executor<IoObject>::value
0230     >* = 0,
0231     enable_if_t<
0232       !execution::is_executor<IoObject>::value
0233     >* = 0)
0234 {
0235   return io_object.get_executor();
0236 }
0237 
0238 template <typename Executor>
0239 inline const Executor& get_composed_io_executor(const Executor& ex,
0240     enable_if_t<
0241       is_executor<Executor>::value
0242         || execution::is_executor<Executor>::value
0243     >* = 0)
0244 {
0245   return ex;
0246 }
0247 
0248 } // namespace detail
0249 } // namespace asio
0250 } // namespace boost
0251 
0252 #include <boost/asio/detail/pop_options.hpp>
0253 
0254 #endif // BOOST_ASIO_DETAIL_COMPOSED_WORK_HPP