diff --git a/example/simple.cpp b/example/simple.cpp index 1c0bd1a..f8743d7 100644 --- a/example/simple.cpp +++ b/example/simple.cpp @@ -9,12 +9,18 @@ #include +using namespace boost::coroutines2; + +asymmetric_coroutine::pull_type make_dummy_range() +{ + return asymmetric_coroutine::pull_type([](asymmetric_coroutine::push_type& yield) + { + yield(1); + }); +} + int main() { - boost::coroutines2::coroutine< void >::push_type sink( - []( boost::coroutines2::coroutine< void >::pull_type & source) { - std::cout << "inside coroutine-fn" << std::endl; - }); - sink(); + std::distance(make_dummy_range()); // error std::cout << "Done" << std::endl; return EXIT_SUCCESS; } diff --git a/include/boost/coroutine2/detail/coroutine.hpp b/include/boost/coroutine2/detail/coroutine.hpp index 83021b6..7c1483d 100644 --- a/include/boost/coroutine2/detail/coroutine.hpp +++ b/include/boost/coroutine2/detail/coroutine.hpp @@ -8,6 +8,7 @@ #define BOOST_COROUTINES2_DETAIL_COROUTINE_HPP #include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -28,24 +29,25 @@ class push_coroutine; #include #include -#if ! defined(BOOST_USE_EXECUTION_CONTEXT) -#include -#include -#else -#include -#include -#endif +#if defined(BOOST_EXECUTION_CONTEXT) +# if (BOOST_EXECUTION_CONTEXT==1) +# include +# include +# else +# include +# include +# endif -#include -#include +# include +# include -#if ! defined(BOOST_USE_EXECUTION_CONTEXT) -#include -#include -#include -#else -#include -#include +# if (BOOST_EXECUTION_CONTEXT==1) +# include +# include +# else +# include +# include +# endif #endif #ifdef BOOST_HAS_ABI_HEADERS diff --git a/include/boost/coroutine2/detail/pull_control_block_ec.hpp b/include/boost/coroutine2/detail/pull_control_block_ecv1.hpp similarity index 100% rename from include/boost/coroutine2/detail/pull_control_block_ec.hpp rename to include/boost/coroutine2/detail/pull_control_block_ecv1.hpp diff --git a/include/boost/coroutine2/detail/pull_control_block_ec.ipp b/include/boost/coroutine2/detail/pull_control_block_ecv1.ipp similarity index 100% rename from include/boost/coroutine2/detail/pull_control_block_ec.ipp rename to include/boost/coroutine2/detail/pull_control_block_ecv1.ipp diff --git a/include/boost/coroutine2/detail/pull_control_block_cc.hpp b/include/boost/coroutine2/detail/pull_control_block_ecv2.hpp similarity index 88% rename from include/boost/coroutine2/detail/pull_control_block_cc.hpp rename to include/boost/coroutine2/detail/pull_control_block_ecv2.hpp index 4fd72a3..58d2488 100644 --- a/include/boost/coroutine2/detail/pull_control_block_cc.hpp +++ b/include/boost/coroutine2/detail/pull_control_block_ecv2.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include @@ -25,7 +25,7 @@ namespace detail { template< typename T > struct pull_coroutine< T >::control_block { - boost::context::captured_context ctx; + boost::context::execution_context< T * > ctx; typename push_coroutine< T >::control_block * other; state_t state; std::exception_ptr except; @@ -37,7 +37,7 @@ struct pull_coroutine< T >::control_block { template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&); - control_block( typename push_coroutine< T >::control_block *, boost::context::captured_context &) noexcept; + control_block( typename push_coroutine< T >::control_block *, boost::context::execution_context< T * > &) noexcept; ~control_block(); @@ -57,7 +57,7 @@ struct pull_coroutine< T >::control_block { template< typename T > struct pull_coroutine< T & >::control_block { - boost::context::captured_context ctx; + boost::context::execution_context< T * > ctx; typename push_coroutine< T & >::control_block * other; state_t state; std::exception_ptr except; @@ -68,7 +68,7 @@ struct pull_coroutine< T & >::control_block { template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&); - control_block( typename push_coroutine< T & >::control_block *, boost::context::captured_context &) noexcept; + control_block( typename push_coroutine< T & >::control_block *, boost::context::execution_context< T * > &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; @@ -83,7 +83,7 @@ struct pull_coroutine< T & >::control_block { }; struct pull_coroutine< void >::control_block { - boost::context::captured_context ctx; + boost::context::execution_context< void > ctx; push_coroutine< void >::control_block * other; state_t state; std::exception_ptr except; @@ -93,7 +93,7 @@ struct pull_coroutine< void >::control_block { template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&); - control_block( push_coroutine< void >::control_block *, boost::context::captured_context &) noexcept; + control_block( push_coroutine< void >::control_block *, boost::context::execution_context< void > &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; diff --git a/include/boost/coroutine2/detail/pull_control_block_cc.ipp b/include/boost/coroutine2/detail/pull_control_block_ecv2.ipp similarity index 85% rename from include/boost/coroutine2/detail/pull_control_block_cc.ipp rename to include/boost/coroutine2/detail/pull_control_block_ecv2.ipp index 1933030..785bc59 100644 --- a/include/boost/coroutine2/detail/pull_control_block_cc.ipp +++ b/include/boost/coroutine2/detail/pull_control_block_ecv2.ipp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include @@ -33,11 +33,11 @@ namespace detail { template< typename T > void pull_coroutine< T >::control_block::destroy( control_block * cb) noexcept { - boost::context::captured_context ctx = std::move( cb->ctx); + boost::context::execution_context< T * > ctx = std::move( cb->ctx); // destroy control structure cb->~control_block(); // destroy coroutine's stack - ctx(); + ctx( nullptr); } template< typename T > @@ -48,7 +48,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, ctx{ std::allocator_arg, palloc, salloc, std::move( std::bind( - [this]( typename std::decay< Fn >::type & fn_, boost::context::captured_context ctx, void *) mutable { + [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context< T * > ctx, T *) mutable { // create synthesized push_coroutine< T > typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; push_coroutine< T > synthesized{ & synthesized_cb }; @@ -66,7 +66,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }, @@ -75,7 +75,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, std::placeholders::_2))}, #else ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=std::forward< Fn >( fn)]( boost::context::captured_context ctx, void *) mutable { + [this,fn_=std::forward< Fn >( fn)]( boost::context::execution_context< T * > ctx, T *) mutable { // create synthesized push_coroutine< T > typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; push_coroutine< T > synthesized{ & synthesized_cb }; @@ -93,7 +93,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }}, @@ -104,14 +104,14 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, bvalid{ false }, storage{} { // enter coroutine-fn in order to have first value available after ctor (of `*this`) returns - auto result = ctx(); + auto result = ctx( nullptr); ctx = std::move( std::get< 0 >( result) ); - set( static_cast< T * >( std::get< 1 >( result) ) ); + set( std::get< 1 >( result) ); } template< typename T > pull_coroutine< T >::control_block::control_block( typename push_coroutine< T >::control_block * cb, - boost::context::captured_context & ctx_) noexcept : + boost::context::execution_context< T * > & ctx_) noexcept : ctx{ std::move( ctx_) }, other{ cb }, state{ state_t::none }, @@ -139,9 +139,9 @@ pull_coroutine< T >::control_block::deallocate() noexcept { template< typename T > void pull_coroutine< T >::control_block::resume() { - auto result = ctx(); + auto result = ctx( nullptr); ctx = std::move( std::get< 0 >( result) ); - set( static_cast< T * >( std::get< 1 >( result) ) ); + set( std::get< 1 >( result) ); if ( except) { std::rethrow_exception( except); } @@ -180,11 +180,11 @@ pull_coroutine< T >::control_block::valid() const noexcept { template< typename T > void pull_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { - boost::context::captured_context ctx = std::move( cb->ctx); + boost::context::execution_context< T * > ctx = std::move( cb->ctx); // destroy control structure cb->~control_block(); // destroy coroutine's stack - ctx(); + ctx( nullptr); } template< typename T > @@ -195,8 +195,8 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo ctx{ std::allocator_arg, palloc, salloc, std::move( std::bind( - [this]( typename std::decay< Fn >::type & fn_, boost::context::captured_context ctx, void *) mutable { - // create synthesized push_coroutine< T > + [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context< T *> ctx, T *) mutable { + // create synthesized push_coroutine< T & > typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; push_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; @@ -213,7 +213,7 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }, @@ -222,8 +222,8 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo std::placeholders::_2))}, #else ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=std::forward< Fn >( fn)]( boost::context::captured_context ctx, void *) mutable { - // create synthesized push_coroutine< T > + [this,fn_=std::forward< Fn >( fn)]( boost::context::execution_context< T * > ctx, T *) mutable { + // create synthesized push_coroutine< T & > typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; push_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; @@ -240,7 +240,7 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }}, @@ -250,14 +250,14 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo except{}, t{ nullptr } { // enter coroutine-fn in order to have first value available after ctor (of `*this`) returns - auto result = ctx(); + auto result = ctx( nullptr); ctx = std::move( std::get< 0 >( result) ); - t = static_cast< T * >( std::get< 1 >( result) ); + t = std::get< 1 >( result); } template< typename T > pull_coroutine< T & >::control_block::control_block( typename push_coroutine< T & >::control_block * cb, - boost::context::captured_context & ctx_) noexcept : + boost::context::execution_context< T * > & ctx_) noexcept : ctx{ std::move( ctx_) }, other{ cb }, state{ state_t::none }, @@ -276,9 +276,9 @@ pull_coroutine< T & >::control_block::deallocate() noexcept { template< typename T > void pull_coroutine< T & >::control_block::resume() { - auto result = ctx(); + auto result = ctx( nullptr); ctx = std::move( std::get< 0 >( result) ); - t = static_cast< T * >( std::get< 1 >( result) ); + t = std::get< 1 >( result); if ( except) { std::rethrow_exception( except); } @@ -287,7 +287,7 @@ pull_coroutine< T & >::control_block::resume() { template< typename T > T & pull_coroutine< T & >::control_block::get() noexcept { - return * static_cast< T * >( t); + return * t; } template< typename T > @@ -302,7 +302,7 @@ pull_coroutine< T & >::control_block::valid() const noexcept { inline void pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept { - boost::context::captured_context ctx = std::move( cb->ctx); + boost::context::execution_context< void > ctx = std::move( cb->ctx); // destroy control structure cb->~control_block(); // destroy coroutine's stack @@ -316,8 +316,8 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall ctx{ std::allocator_arg, palloc, salloc, std::move( std::bind( - [this]( typename std::decay< Fn >::type & fn_, boost::context::captured_context ctx, void *) mutable { - // create synthesized push_coroutine< T > + [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context< void > ctx) mutable { + // create synthesized push_coroutine< void > typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; push_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; @@ -334,17 +334,15 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); - other->ctx = std::move( std::get< 0 >( result) ); + other->ctx = other->ctx(); return std::move( other->ctx); }, std::forward< Fn >( fn), - std::placeholders::_1, - std::placeholders::_2))}, + std::placeholders::_1))}, #else ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=std::forward< Fn >( fn)]( boost::context::captured_context ctx, void *) mutable { - // create synthesized push_coroutine< T > + [this,fn_=std::forward< Fn >( fn)]( boost::context::execution_context< void > ctx) mutable { + // create synthesized push_coroutine< void > typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; push_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; @@ -361,8 +359,7 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); - other->ctx = std::move( std::get< 0 >( result) ); + other->ctx = other->ctx(); return std::move( other->ctx); }}, #endif @@ -370,13 +367,12 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall state{ state_t::unwind }, except{} { // enter coroutine-fn in order to have first value available after ctor (of `*this`) returns - auto result = ctx(); - ctx = std::move( std::get< 0 >( result) ); + ctx = ctx(); } inline pull_coroutine< void >::control_block::control_block( push_coroutine< void >::control_block * cb, - boost::context::captured_context & ctx_) noexcept : + boost::context::execution_context< void > & ctx_) noexcept : ctx{ std::move( ctx_) }, other{ cb }, state{ state_t::none }, @@ -394,8 +390,7 @@ pull_coroutine< void >::control_block::deallocate() noexcept { inline void pull_coroutine< void >::control_block::resume() { - auto result = ctx(); - ctx = std::move( std::get< 0 >( result) ); + ctx = ctx(); if ( except) { std::rethrow_exception( except); } diff --git a/include/boost/coroutine2/detail/push_control_block_ec.hpp b/include/boost/coroutine2/detail/push_control_block_ecv1.hpp similarity index 100% rename from include/boost/coroutine2/detail/push_control_block_ec.hpp rename to include/boost/coroutine2/detail/push_control_block_ecv1.hpp diff --git a/include/boost/coroutine2/detail/push_control_block_ec.ipp b/include/boost/coroutine2/detail/push_control_block_ecv1.ipp similarity index 100% rename from include/boost/coroutine2/detail/push_control_block_ec.ipp rename to include/boost/coroutine2/detail/push_control_block_ecv1.ipp diff --git a/include/boost/coroutine2/detail/push_control_block_cc.hpp b/include/boost/coroutine2/detail/push_control_block_ecv2.hpp similarity index 87% rename from include/boost/coroutine2/detail/push_control_block_cc.hpp rename to include/boost/coroutine2/detail/push_control_block_ecv2.hpp index ac4ab61..feb5e4a 100644 --- a/include/boost/coroutine2/detail/push_control_block_cc.hpp +++ b/include/boost/coroutine2/detail/push_control_block_ecv2.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include @@ -24,7 +24,7 @@ namespace detail { template< typename T > struct push_coroutine< T >::control_block { - boost::context::captured_context ctx; + boost::context::execution_context< T * > ctx; typename pull_coroutine< T >::control_block * other; state_t state; std::exception_ptr except; @@ -34,7 +34,7 @@ struct push_coroutine< T >::control_block { template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&); - control_block( typename pull_coroutine< T >::control_block *, boost::context::captured_context &) noexcept; + control_block( typename pull_coroutine< T >::control_block *, boost::context::execution_context< T * > &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; @@ -50,7 +50,7 @@ struct push_coroutine< T >::control_block { template< typename T > struct push_coroutine< T & >::control_block { - boost::context::captured_context ctx; + boost::context::execution_context< T * > ctx; typename pull_coroutine< T & >::control_block * other; state_t state; std::exception_ptr except; @@ -60,7 +60,7 @@ struct push_coroutine< T & >::control_block { template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&); - control_block( typename pull_coroutine< T & >::control_block *, boost::context::captured_context &) noexcept; + control_block( typename pull_coroutine< T & >::control_block *, boost::context::execution_context< T * > &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; @@ -73,7 +73,7 @@ struct push_coroutine< T & >::control_block { }; struct push_coroutine< void >::control_block { - boost::context::captured_context ctx; + boost::context::execution_context< void > ctx; pull_coroutine< void >::control_block * other; state_t state; std::exception_ptr except; @@ -83,7 +83,7 @@ struct push_coroutine< void >::control_block { template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&); - control_block( pull_coroutine< void >::control_block *, boost::context::captured_context &) noexcept; + control_block( pull_coroutine< void >::control_block *, boost::context::execution_context< void > &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; diff --git a/include/boost/coroutine2/detail/push_control_block_cc.ipp b/include/boost/coroutine2/detail/push_control_block_ecv2.ipp similarity index 86% rename from include/boost/coroutine2/detail/push_control_block_cc.ipp rename to include/boost/coroutine2/detail/push_control_block_ecv2.ipp index 78a6394..bfdee06 100644 --- a/include/boost/coroutine2/detail/push_control_block_cc.ipp +++ b/include/boost/coroutine2/detail/push_control_block_ecv2.ipp @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include @@ -32,11 +32,11 @@ namespace detail { template< typename T > void push_coroutine< T >::control_block::destroy( control_block * cb) noexcept { - boost::context::captured_context ctx = std::move( cb->ctx); + boost::context::execution_context< T * > ctx = std::move( cb->ctx); // destroy control structure cb->~control_block(); // destroy coroutine's stack - ctx(); + ctx( nullptr); } template< typename T > @@ -47,13 +47,13 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, ctx{ std::allocator_arg, palloc, salloc, std::move( std::bind( - [this]( typename std::decay< Fn >::type & fn_, boost::context::captured_context ctx, void * data) mutable { + [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context< T * > ctx, T * data) mutable { // create synthesized pull_coroutine< T > typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx }; pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; // set transferred value - synthesized_cb.set( static_cast< T * >( data) ); + synthesized_cb.set( data); try { auto fn = std::move( fn_); // call coroutine-fn with synthesized pull_coroutine as argument @@ -67,7 +67,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }, @@ -76,13 +76,13 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, std::placeholders::_2))}, #else ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=std::forward< Fn >( fn)]( boost::context::captured_context ctx, void * data) mutable { + [this,fn_=std::forward< Fn >( fn)]( boost::context::execution_context< T * > ctx, T * data) mutable { // create synthesized pull_coroutine< T > typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx }; pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; // set transferred value - synthesized_cb.set( static_cast< T * >( data) ); + synthesized_cb.set( data); try { auto fn = std::move( fn_); // call coroutine-fn with synthesized pull_coroutine as argument @@ -96,7 +96,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }}, @@ -108,7 +108,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, template< typename T > push_coroutine< T >::control_block::control_block( typename pull_coroutine< T >::control_block * cb, - boost::context::captured_context & ctx_) noexcept : + boost::context::execution_context< T * > & ctx_) noexcept : ctx{ std::move( ctx_) }, other{ cb }, state{ state_t::none }, @@ -157,11 +157,11 @@ push_coroutine< T >::control_block::valid() const noexcept { template< typename T > void push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { - boost::context::captured_context ctx = std::move( cb->ctx); + boost::context::execution_context< T * > ctx = std::move( cb->ctx); // destroy control structure cb->~control_block(); // destroy coroutine's stack - ctx(); + ctx( nullptr); } template< typename T > @@ -172,13 +172,13 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo ctx{ std::allocator_arg, palloc, salloc, std::move( std::bind( - [this]( typename std::decay< Fn >::type & fn_, boost::context::captured_context ctx, void * data) mutable { - // create synthesized pull_coroutine< T > + [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context< T * > ctx, T * data) mutable { + // create synthesized pull_coroutine< T & > typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx }; pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; // set transferred value - synthesized_cb.t = static_cast< T * >( data); + synthesized_cb.t = data; try { auto fn = std::move( fn_); // call coroutine-fn with synthesized pull_coroutine as argument @@ -192,7 +192,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }, @@ -201,13 +201,13 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo std::placeholders::_2))}, #else ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=std::forward< Fn >( fn)]( boost::context::captured_context ctx, void * data) mutable { - // create synthesized pull_coroutine< T > + [this,fn_=std::forward< Fn >( fn)]( boost::context::execution_context< T * > ctx, T * data) mutable { + // create synthesized pull_coroutine< T & > typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx }; pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; // set transferred value - synthesized_cb.t = static_cast< T * >( data); + synthesized_cb.t = data; try { auto fn = std::move( fn_); // call coroutine-fn with synthesized pull_coroutine as argument @@ -221,7 +221,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); + auto result = other->ctx( nullptr); other->ctx = std::move( std::get< 0 >( result) ); return std::move( other->ctx); }}, @@ -233,7 +233,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo template< typename T > push_coroutine< T & >::control_block::control_block( typename pull_coroutine< T & >::control_block * cb, - boost::context::captured_context & ctx_) noexcept : + boost::context::execution_context< T * > & ctx_) noexcept : ctx{ std::move( ctx_) }, other{ cb }, state{ state_t::none }, @@ -271,7 +271,7 @@ push_coroutine< T & >::control_block::valid() const noexcept { inline void push_coroutine< void >::control_block::destroy( control_block * cb) noexcept { - boost::context::captured_context ctx = std::move( cb->ctx); + boost::context::execution_context< void > ctx = std::move( cb->ctx); // destroy control structure cb->~control_block(); // destroy coroutine's stack @@ -284,8 +284,8 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall ctx{ std::allocator_arg, palloc, salloc, std::move( std::bind( - [this]( typename std::decay< Fn >::type & fn_, boost::context::captured_context ctx, void *) mutable { - // create synthesized pull_coroutine< T > + [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context< void > ctx) mutable { + // create synthesized pull_coroutine< void > typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx }; pull_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; @@ -302,17 +302,15 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); - other->ctx = std::move( std::get< 0 >( result) ); + other->ctx = other->ctx(); return std::move( other->ctx); }, std::forward< Fn >( fn), - std::placeholders::_1, - std::placeholders::_2))}, + std::placeholders::_1))}, #else ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=std::forward< Fn >( fn)]( boost::context::captured_context ctx, void *) mutable { - // create synthesized pull_coroutine< T > + [this,fn_=std::forward< Fn >( fn)]( boost::context::execution_context< void > ctx) mutable { + // create synthesized pull_coroutine< void > typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx}; pull_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; @@ -329,8 +327,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall // set termination flags state |= state_t::complete; // jump back to ctx - auto result = other->ctx(); - other->ctx = std::move( std::get< 0 >( result) ); + other->ctx = other->ctx(); return std::move( other->ctx); }}, #endif @@ -341,7 +338,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall inline push_coroutine< void >::control_block::control_block( pull_coroutine< void >::control_block * cb, - boost::context::captured_context & ctx_) noexcept : + boost::context::execution_context< void > & ctx_) noexcept : ctx{ std::move( ctx_) }, other{ cb }, state{ state_t::none }, @@ -359,8 +356,7 @@ push_coroutine< void >::control_block::deallocate() noexcept { inline void push_coroutine< void >::control_block::resume() { - auto result = ctx(); - ctx = std::move( std::get< 0 >( result) ); + ctx = ctx(); if ( except) { std::rethrow_exception( except); }