Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:46

0001 //
0002 // this_coro.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_THIS_CORO_HPP
0012 #define BOOST_ASIO_THIS_CORO_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 
0021 #include <boost/asio/detail/push_options.hpp>
0022 
0023 namespace boost {
0024 namespace asio {
0025 namespace this_coro {
0026 
0027 /// Awaitable type that returns the executor of the current coroutine.
0028 struct executor_t
0029 {
0030   constexpr executor_t()
0031   {
0032   }
0033 };
0034 
0035 /// Awaitable object that returns the executor of the current coroutine.
0036 constexpr executor_t executor;
0037 
0038 /// Awaitable type that returns the cancellation state of the current coroutine.
0039 struct cancellation_state_t
0040 {
0041   constexpr cancellation_state_t()
0042   {
0043   }
0044 };
0045 
0046 /// Awaitable object that returns the cancellation state of the current
0047 /// coroutine.
0048 /**
0049  * @par Example
0050  * @code boost::asio::awaitable<void> my_coroutine()
0051  * {
0052  *   boost::asio::cancellation_state cs
0053  *     = co_await boost::asio::this_coro::cancellation_state;
0054  *
0055  *   // ...
0056  *
0057  *   if (cs.cancelled() != boost::asio::cancellation_type::none)
0058  *     // ...
0059  * } @endcode
0060  */
0061 constexpr cancellation_state_t cancellation_state;
0062 
0063 #if defined(GENERATING_DOCUMENTATION)
0064 
0065 /// Returns an awaitable object that may be used to reset the cancellation state
0066 /// of the current coroutine.
0067 /**
0068  * Let <tt>P</tt> be the cancellation slot associated with the current
0069  * coroutine's @ref co_spawn completion handler. Assigns a new
0070  * boost::asio::cancellation_state object <tt>S</tt>, constructed as
0071  * <tt>S(P)</tt>, into the current coroutine's cancellation state object.
0072  *
0073  * @par Example
0074  * @code boost::asio::awaitable<void> my_coroutine()
0075  * {
0076  *   co_await boost::asio::this_coro::reset_cancellation_state();
0077  *
0078  *   // ...
0079  * } @endcode
0080  *
0081  * @note The cancellation state is shared by all coroutines in the same "thread
0082  * of execution" that was created using boost::asio::co_spawn.
0083  */
0084 BOOST_ASIO_NODISCARD constexpr unspecified
0085 reset_cancellation_state();
0086 
0087 /// Returns an awaitable object that may be used to reset the cancellation state
0088 /// of the current coroutine.
0089 /**
0090  * Let <tt>P</tt> be the cancellation slot associated with the current
0091  * coroutine's @ref co_spawn completion handler. Assigns a new
0092  * boost::asio::cancellation_state object <tt>S</tt>, constructed as <tt>S(P,
0093  * std::forward<Filter>(filter))</tt>, into the current coroutine's
0094  * cancellation state object.
0095  *
0096  * @par Example
0097  * @code boost::asio::awaitable<void> my_coroutine()
0098  * {
0099  *   co_await boost::asio::this_coro::reset_cancellation_state(
0100  *       boost::asio::enable_partial_cancellation());
0101  *
0102  *   // ...
0103  * } @endcode
0104  *
0105  * @note The cancellation state is shared by all coroutines in the same "thread
0106  * of execution" that was created using boost::asio::co_spawn.
0107  */
0108 template <typename Filter>
0109 BOOST_ASIO_NODISCARD constexpr unspecified
0110 reset_cancellation_state(Filter&& filter);
0111 
0112 /// Returns an awaitable object that may be used to reset the cancellation state
0113 /// of the current coroutine.
0114 /**
0115  * Let <tt>P</tt> be the cancellation slot associated with the current
0116  * coroutine's @ref co_spawn completion handler. Assigns a new
0117  * boost::asio::cancellation_state object <tt>S</tt>, constructed as <tt>S(P,
0118  * std::forward<InFilter>(in_filter),
0119  * std::forward<OutFilter>(out_filter))</tt>, into the current coroutine's
0120  * cancellation state object.
0121  *
0122  * @par Example
0123  * @code boost::asio::awaitable<void> my_coroutine()
0124  * {
0125  *   co_await boost::asio::this_coro::reset_cancellation_state(
0126  *       boost::asio::enable_partial_cancellation(),
0127  *       boost::asio::disable_cancellation());
0128  *
0129  *   // ...
0130  * } @endcode
0131  *
0132  * @note The cancellation state is shared by all coroutines in the same "thread
0133  * of execution" that was created using boost::asio::co_spawn.
0134  */
0135 template <typename InFilter, typename OutFilter>
0136 BOOST_ASIO_NODISCARD constexpr unspecified
0137 reset_cancellation_state(
0138     InFilter&& in_filter,
0139     OutFilter&& out_filter);
0140 
0141 /// Returns an awaitable object that may be used to determine whether the
0142 /// coroutine throws if trying to suspend when it has been cancelled.
0143 /**
0144  * @par Example
0145  * @code boost::asio::awaitable<void> my_coroutine()
0146  * {
0147  *   if (co_await boost::asio::this_coro::throw_if_cancelled)
0148  *     // ...
0149  *
0150  *   // ...
0151  * } @endcode
0152  */
0153 BOOST_ASIO_NODISCARD constexpr unspecified
0154 throw_if_cancelled();
0155 
0156 /// Returns an awaitable object that may be used to specify whether the
0157 /// coroutine throws if trying to suspend when it has been cancelled.
0158 /**
0159  * @par Example
0160  * @code boost::asio::awaitable<void> my_coroutine()
0161  * {
0162  *   co_await boost::asio::this_coro::throw_if_cancelled(false);
0163  *
0164  *   // ...
0165  * } @endcode
0166  */
0167 BOOST_ASIO_NODISCARD constexpr unspecified
0168 throw_if_cancelled(bool value);
0169 
0170 #else // defined(GENERATING_DOCUMENTATION)
0171 
0172 struct reset_cancellation_state_0_t
0173 {
0174   constexpr reset_cancellation_state_0_t()
0175   {
0176   }
0177 };
0178 
0179 BOOST_ASIO_NODISCARD inline constexpr reset_cancellation_state_0_t
0180 reset_cancellation_state()
0181 {
0182   return reset_cancellation_state_0_t();
0183 }
0184 
0185 template <typename Filter>
0186 struct reset_cancellation_state_1_t
0187 {
0188   template <typename F>
0189   explicit constexpr reset_cancellation_state_1_t(
0190       F&& filt)
0191     : filter(static_cast<F&&>(filt))
0192   {
0193   }
0194 
0195   Filter filter;
0196 };
0197 
0198 template <typename Filter>
0199 BOOST_ASIO_NODISCARD inline constexpr reset_cancellation_state_1_t<
0200     decay_t<Filter>>
0201 reset_cancellation_state(Filter&& filter)
0202 {
0203   return reset_cancellation_state_1_t<decay_t<Filter>>(
0204       static_cast<Filter&&>(filter));
0205 }
0206 
0207 template <typename InFilter, typename OutFilter>
0208 struct reset_cancellation_state_2_t
0209 {
0210   template <typename F1, typename F2>
0211   constexpr reset_cancellation_state_2_t(
0212       F1&& in_filt, F2&& out_filt)
0213     : in_filter(static_cast<F1&&>(in_filt)),
0214       out_filter(static_cast<F2&&>(out_filt))
0215   {
0216   }
0217 
0218   InFilter in_filter;
0219   OutFilter out_filter;
0220 };
0221 
0222 template <typename InFilter, typename OutFilter>
0223 BOOST_ASIO_NODISCARD inline constexpr
0224 reset_cancellation_state_2_t<decay_t<InFilter>, decay_t<OutFilter>>
0225 reset_cancellation_state(InFilter&& in_filter, OutFilter&& out_filter)
0226 {
0227   return reset_cancellation_state_2_t<decay_t<InFilter>, decay_t<OutFilter>>(
0228       static_cast<InFilter&&>(in_filter),
0229       static_cast<OutFilter&&>(out_filter));
0230 }
0231 
0232 struct throw_if_cancelled_0_t
0233 {
0234   constexpr throw_if_cancelled_0_t()
0235   {
0236   }
0237 };
0238 
0239 BOOST_ASIO_NODISCARD inline constexpr throw_if_cancelled_0_t
0240 throw_if_cancelled()
0241 {
0242   return throw_if_cancelled_0_t();
0243 }
0244 
0245 struct throw_if_cancelled_1_t
0246 {
0247   explicit constexpr throw_if_cancelled_1_t(bool val)
0248     : value(val)
0249   {
0250   }
0251 
0252   bool value;
0253 };
0254 
0255 BOOST_ASIO_NODISCARD inline constexpr throw_if_cancelled_1_t
0256 throw_if_cancelled(bool value)
0257 {
0258   return throw_if_cancelled_1_t(value);
0259 }
0260 
0261 #endif // defined(GENERATING_DOCUMENTATION)
0262 
0263 } // namespace this_coro
0264 } // namespace asio
0265 } // namespace boost
0266 
0267 #include <boost/asio/detail/pop_options.hpp>
0268 
0269 #endif // BOOST_ASIO_THIS_CORO_HPP