File indexing completed on 2025-01-18 09:30:33
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP
0008 #define BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP
0009
0010 #include <exception>
0011 #include <type_traits>
0012
0013 #include <boost/config.hpp>
0014 #include <boost/context/fiber.hpp>
0015
0016 #include <boost/coroutine2/detail/state.hpp>
0017
0018 #ifdef BOOST_HAS_ABI_HEADERS
0019 # include BOOST_ABI_PREFIX
0020 #endif
0021
0022 namespace boost {
0023 namespace coroutines2 {
0024 namespace detail {
0025
0026 template< typename T >
0027 struct pull_coroutine< T >::control_block {
0028 boost::context::fiber c;
0029 typename push_coroutine< T >::control_block * other;
0030 state_t state;
0031 std::exception_ptr except;
0032 bool bvalid;
0033 typename std::aligned_storage< sizeof( T), alignof( T) >::type storage;
0034
0035 static void destroy( control_block * cb) noexcept;
0036
0037 template< typename StackAllocator, typename Fn >
0038 control_block( context::preallocated, StackAllocator &&, Fn &&);
0039
0040 control_block( typename push_coroutine< T >::control_block *, boost::context::fiber &) noexcept;
0041
0042 ~control_block();
0043
0044 control_block( control_block &) = delete;
0045 control_block & operator=( control_block &) = delete;
0046
0047 void deallocate() noexcept;
0048
0049 void resume();
0050
0051 void set( T const&);
0052 void set( T &&);
0053
0054 T & get() noexcept;
0055
0056 bool valid() const noexcept;
0057 };
0058
0059 template< typename T >
0060 struct pull_coroutine< T & >::control_block {
0061 struct holder {
0062 T & t;
0063
0064 holder( T & t_) :
0065 t{ t_ } {
0066 }
0067 };
0068
0069 boost::context::fiber c;
0070 typename push_coroutine< T & >::control_block * other;
0071 state_t state;
0072 std::exception_ptr except;
0073 bool bvalid;
0074 typename std::aligned_storage< sizeof( holder), alignof( holder) >::type storage;
0075
0076 static void destroy( control_block * cb) noexcept;
0077
0078 template< typename StackAllocator, typename Fn >
0079 control_block( context::preallocated, StackAllocator &&, Fn &&);
0080
0081 control_block( typename push_coroutine< T & >::control_block *, boost::context::fiber &) noexcept;
0082
0083 control_block( control_block &) = delete;
0084 control_block & operator=( control_block &) = delete;
0085
0086 void deallocate() noexcept;
0087
0088 void resume();
0089
0090 void set( T &);
0091
0092 T & get() noexcept;
0093
0094 bool valid() const noexcept;
0095 };
0096
0097 struct pull_coroutine< void >::control_block {
0098 boost::context::fiber c;
0099 push_coroutine< void >::control_block * other;
0100 state_t state;
0101 std::exception_ptr except;
0102
0103 static void destroy( control_block * cb) noexcept;
0104
0105 template< typename StackAllocator, typename Fn >
0106 control_block( context::preallocated, StackAllocator &&, Fn &&);
0107
0108 control_block( push_coroutine< void >::control_block *, boost::context::fiber &) noexcept;
0109
0110 control_block( control_block &) = delete;
0111 control_block & operator=( control_block &) = delete;
0112
0113 void deallocate() noexcept;
0114
0115 void resume();
0116
0117 bool valid() const noexcept;
0118 };
0119
0120 }}}
0121
0122 #ifdef BOOST_HAS_ABI_HEADERS
0123 # include BOOST_ABI_SUFFIX
0124 #endif
0125
0126 #endif