Merge branch 'develop'

This commit is contained in:
Oliver Kowalke 2016-02-11 19:14:18 +01:00
commit be189f21db
10 changed files with 111 additions and 112 deletions

View File

@ -9,12 +9,18 @@
#include <boost/coroutine2/all.hpp> #include <boost/coroutine2/all.hpp>
int main() { using namespace boost::coroutines2;
boost::coroutines2::coroutine< void >::push_type sink(
[]( boost::coroutines2::coroutine< void >::pull_type & source) { asymmetric_coroutine<int>::pull_type make_dummy_range()
std::cout << "inside coroutine-fn" << std::endl; {
return asymmetric_coroutine<int>::pull_type([](asymmetric_coroutine<int>::push_type& yield)
{
yield(1);
}); });
sink(); }
int main() {
std::distance(make_dummy_range()); // error
std::cout << "Done" << std::endl; std::cout << "Done" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -8,6 +8,7 @@
#define BOOST_COROUTINES2_DETAIL_COROUTINE_HPP #define BOOST_COROUTINES2_DETAIL_COROUTINE_HPP
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/context/detail/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS #ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX # include BOOST_ABI_PREFIX
@ -28,24 +29,25 @@ class push_coroutine;
#include <boost/coroutine2/detail/pull_coroutine.hpp> #include <boost/coroutine2/detail/pull_coroutine.hpp>
#include <boost/coroutine2/detail/push_coroutine.hpp> #include <boost/coroutine2/detail/push_coroutine.hpp>
#if ! defined(BOOST_USE_EXECUTION_CONTEXT) #if defined(BOOST_EXECUTION_CONTEXT)
#include <boost/coroutine2/detail/pull_control_block_cc.hpp> # if (BOOST_EXECUTION_CONTEXT==1)
#include <boost/coroutine2/detail/push_control_block_cc.hpp> # include <boost/coroutine2/detail/pull_control_block_ecv1.hpp>
# include <boost/coroutine2/detail/push_control_block_ecv1.hpp>
# else # else
#include <boost/coroutine2/detail/pull_control_block_ec.hpp> # include <boost/coroutine2/detail/pull_control_block_ecv2.hpp>
#include <boost/coroutine2/detail/push_control_block_ec.hpp> # include <boost/coroutine2/detail/push_control_block_ecv2.hpp>
# endif # endif
# include <boost/coroutine2/detail/pull_coroutine.ipp> # include <boost/coroutine2/detail/pull_coroutine.ipp>
# include <boost/coroutine2/detail/push_coroutine.ipp> # include <boost/coroutine2/detail/push_coroutine.ipp>
#if ! defined(BOOST_USE_EXECUTION_CONTEXT) # if (BOOST_EXECUTION_CONTEXT==1)
#include <boost/coroutine2/detail/pull_control_block_cc.hpp> # include <boost/coroutine2/detail/pull_control_block_ecv1.ipp>
#include <boost/coroutine2/detail/pull_control_block_cc.ipp> # include <boost/coroutine2/detail/push_control_block_ecv1.ipp>
#include <boost/coroutine2/detail/push_control_block_cc.ipp>
# else # else
#include <boost/coroutine2/detail/pull_control_block_ec.ipp> # include <boost/coroutine2/detail/pull_control_block_ecv2.ipp>
#include <boost/coroutine2/detail/push_control_block_ec.ipp> # include <boost/coroutine2/detail/push_control_block_ecv2.ipp>
# endif
#endif #endif
#ifdef BOOST_HAS_ABI_HEADERS #ifdef BOOST_HAS_ABI_HEADERS

View File

@ -11,7 +11,7 @@
#include <type_traits> #include <type_traits>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/context/captured_context.hpp> #include <boost/context/execution_context.hpp>
#include <boost/coroutine2/detail/state.hpp> #include <boost/coroutine2/detail/state.hpp>
@ -25,7 +25,7 @@ namespace detail {
template< typename T > template< typename T >
struct pull_coroutine< T >::control_block { struct pull_coroutine< T >::control_block {
boost::context::captured_context ctx; boost::context::execution_context< T * > ctx;
typename push_coroutine< T >::control_block * other; typename push_coroutine< T >::control_block * other;
state_t state; state_t state;
std::exception_ptr except; std::exception_ptr except;
@ -37,7 +37,7 @@ struct pull_coroutine< T >::control_block {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
control_block( context::preallocated, StackAllocator, 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();
@ -57,7 +57,7 @@ struct pull_coroutine< T >::control_block {
template< typename T > template< typename T >
struct pull_coroutine< T & >::control_block { struct pull_coroutine< T & >::control_block {
boost::context::captured_context ctx; boost::context::execution_context< T * > ctx;
typename push_coroutine< T & >::control_block * other; typename push_coroutine< T & >::control_block * other;
state_t state; state_t state;
std::exception_ptr except; std::exception_ptr except;
@ -68,7 +68,7 @@ struct pull_coroutine< T & >::control_block {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
control_block( context::preallocated, StackAllocator, 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( control_block &) = delete;
control_block & operator=( 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 { struct pull_coroutine< void >::control_block {
boost::context::captured_context ctx; boost::context::execution_context< void > ctx;
push_coroutine< void >::control_block * other; push_coroutine< void >::control_block * other;
state_t state; state_t state;
std::exception_ptr except; std::exception_ptr except;
@ -93,7 +93,7 @@ struct pull_coroutine< void >::control_block {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
control_block( context::preallocated, StackAllocator, 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( control_block &) = delete;
control_block & operator=( control_block &) = delete; control_block & operator=( control_block &) = delete;

View File

@ -15,7 +15,7 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/context/captured_context.hpp> #include <boost/context/execution_context.hpp>
#include <boost/coroutine2/detail/config.hpp> #include <boost/coroutine2/detail/config.hpp>
#include <boost/coroutine2/detail/forced_unwind.hpp> #include <boost/coroutine2/detail/forced_unwind.hpp>
@ -33,11 +33,11 @@ namespace detail {
template< typename T > template< typename T >
void void
pull_coroutine< T >::control_block::destroy( control_block * cb) noexcept { 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 // destroy control structure
cb->~control_block(); cb->~control_block();
// destroy coroutine's stack // destroy coroutine's stack
ctx(); ctx( nullptr);
} }
template< typename T > template< typename T >
@ -48,7 +48,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
ctx{ std::allocator_arg, palloc, salloc, ctx{ std::allocator_arg, palloc, salloc,
std::move( std::move(
std::bind( 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 > // create synthesized push_coroutine< T >
typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; typename push_coroutine< T >::control_block synthesized_cb{ this, ctx };
push_coroutine< T > synthesized{ & synthesized_cb }; push_coroutine< T > synthesized{ & synthesized_cb };
@ -66,7 +66,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}, },
@ -75,7 +75,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
std::placeholders::_2))}, std::placeholders::_2))},
#else #else
ctx{ std::allocator_arg, palloc, salloc, 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 > // create synthesized push_coroutine< T >
typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; typename push_coroutine< T >::control_block synthesized_cb{ this, ctx };
push_coroutine< T > synthesized{ & synthesized_cb }; push_coroutine< T > synthesized{ & synthesized_cb };
@ -93,7 +93,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}}, }},
@ -104,14 +104,14 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
bvalid{ false }, bvalid{ false },
storage{} { storage{} {
// enter coroutine-fn in order to have first value available after ctor (of `*this`) returns // 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) ); ctx = std::move( std::get< 0 >( result) );
set( static_cast< T * >( std::get< 1 >( result) ) ); set( std::get< 1 >( result) );
} }
template< typename T > template< typename T >
pull_coroutine< T >::control_block::control_block( typename push_coroutine< T >::control_block * cb, 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_) }, ctx{ std::move( ctx_) },
other{ cb }, other{ cb },
state{ state_t::none }, state{ state_t::none },
@ -139,9 +139,9 @@ pull_coroutine< T >::control_block::deallocate() noexcept {
template< typename T > template< typename T >
void void
pull_coroutine< T >::control_block::resume() { pull_coroutine< T >::control_block::resume() {
auto result = ctx(); auto result = ctx( nullptr);
ctx = std::move( std::get< 0 >( result) ); ctx = std::move( std::get< 0 >( result) );
set( static_cast< T * >( std::get< 1 >( result) ) ); set( std::get< 1 >( result) );
if ( except) { if ( except) {
std::rethrow_exception( except); std::rethrow_exception( except);
} }
@ -180,11 +180,11 @@ pull_coroutine< T >::control_block::valid() const noexcept {
template< typename T > template< typename T >
void void
pull_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { 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 // destroy control structure
cb->~control_block(); cb->~control_block();
// destroy coroutine's stack // destroy coroutine's stack
ctx(); ctx( nullptr);
} }
template< typename T > template< typename T >
@ -195,8 +195,8 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
ctx{ std::allocator_arg, palloc, salloc, ctx{ std::allocator_arg, palloc, salloc,
std::move( std::move(
std::bind( 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 > // create synthesized push_coroutine< T & >
typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx };
push_coroutine< T & > synthesized{ & synthesized_cb }; push_coroutine< T & > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
@ -213,7 +213,7 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}, },
@ -222,8 +222,8 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
std::placeholders::_2))}, std::placeholders::_2))},
#else #else
ctx{ std::allocator_arg, palloc, salloc, 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 > // create synthesized push_coroutine< T & >
typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx };
push_coroutine< T & > synthesized{ & synthesized_cb }; push_coroutine< T & > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
@ -240,7 +240,7 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}}, }},
@ -250,14 +250,14 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
except{}, except{},
t{ nullptr } { t{ nullptr } {
// enter coroutine-fn in order to have first value available after ctor (of `*this`) returns // 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) ); ctx = std::move( std::get< 0 >( result) );
t = static_cast< T * >( std::get< 1 >( result) ); t = std::get< 1 >( result);
} }
template< typename T > template< typename T >
pull_coroutine< T & >::control_block::control_block( typename push_coroutine< T & >::control_block * cb, 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_) }, ctx{ std::move( ctx_) },
other{ cb }, other{ cb },
state{ state_t::none }, state{ state_t::none },
@ -276,9 +276,9 @@ pull_coroutine< T & >::control_block::deallocate() noexcept {
template< typename T > template< typename T >
void void
pull_coroutine< T & >::control_block::resume() { pull_coroutine< T & >::control_block::resume() {
auto result = ctx(); auto result = ctx( nullptr);
ctx = std::move( std::get< 0 >( result) ); ctx = std::move( std::get< 0 >( result) );
t = static_cast< T * >( std::get< 1 >( result) ); t = std::get< 1 >( result);
if ( except) { if ( except) {
std::rethrow_exception( except); std::rethrow_exception( except);
} }
@ -287,7 +287,7 @@ pull_coroutine< T & >::control_block::resume() {
template< typename T > template< typename T >
T & T &
pull_coroutine< T & >::control_block::get() noexcept { pull_coroutine< T & >::control_block::get() noexcept {
return * static_cast< T * >( t); return * t;
} }
template< typename T > template< typename T >
@ -302,7 +302,7 @@ pull_coroutine< T & >::control_block::valid() const noexcept {
inline inline
void void
pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept { 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 // destroy control structure
cb->~control_block(); cb->~control_block();
// destroy coroutine's stack // destroy coroutine's stack
@ -316,8 +316,8 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
ctx{ std::allocator_arg, palloc, salloc, ctx{ std::allocator_arg, palloc, salloc,
std::move( std::move(
std::bind( 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< void > ctx) mutable {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< void >
typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; typename push_coroutine< void >::control_block synthesized_cb{ this, ctx };
push_coroutine< void > synthesized{ & synthesized_cb }; push_coroutine< void > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
@ -334,17 +334,15 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); other->ctx = other->ctx();
other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}, },
std::forward< Fn >( fn), std::forward< Fn >( fn),
std::placeholders::_1, std::placeholders::_1))},
std::placeholders::_2))},
#else #else
ctx{ std::allocator_arg, palloc, salloc, 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< void > ctx) mutable {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< void >
typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; typename push_coroutine< void >::control_block synthesized_cb{ this, ctx };
push_coroutine< void > synthesized{ & synthesized_cb }; push_coroutine< void > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
@ -361,8 +359,7 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); other->ctx = other->ctx();
other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}}, }},
#endif #endif
@ -370,13 +367,12 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
state{ state_t::unwind }, state{ state_t::unwind },
except{} { except{} {
// enter coroutine-fn in order to have first value available after ctor (of `*this`) returns // enter coroutine-fn in order to have first value available after ctor (of `*this`) returns
auto result = ctx(); ctx = ctx();
ctx = std::move( std::get< 0 >( result) );
} }
inline inline
pull_coroutine< void >::control_block::control_block( push_coroutine< void >::control_block * cb, 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_) }, ctx{ std::move( ctx_) },
other{ cb }, other{ cb },
state{ state_t::none }, state{ state_t::none },
@ -394,8 +390,7 @@ pull_coroutine< void >::control_block::deallocate() noexcept {
inline inline
void void
pull_coroutine< void >::control_block::resume() { pull_coroutine< void >::control_block::resume() {
auto result = ctx(); ctx = ctx();
ctx = std::move( std::get< 0 >( result) );
if ( except) { if ( except) {
std::rethrow_exception( except); std::rethrow_exception( except);
} }

View File

@ -10,7 +10,7 @@
#include <exception> #include <exception>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/context/captured_context.hpp> #include <boost/context/execution_context.hpp>
#include <boost/coroutine2/detail/state.hpp> #include <boost/coroutine2/detail/state.hpp>
@ -24,7 +24,7 @@ namespace detail {
template< typename T > template< typename T >
struct push_coroutine< T >::control_block { struct push_coroutine< T >::control_block {
boost::context::captured_context ctx; boost::context::execution_context< T * > ctx;
typename pull_coroutine< T >::control_block * other; typename pull_coroutine< T >::control_block * other;
state_t state; state_t state;
std::exception_ptr except; std::exception_ptr except;
@ -34,7 +34,7 @@ struct push_coroutine< T >::control_block {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
control_block( context::preallocated, StackAllocator, 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( control_block &) = delete;
control_block & operator=( control_block &) = delete; control_block & operator=( control_block &) = delete;
@ -50,7 +50,7 @@ struct push_coroutine< T >::control_block {
template< typename T > template< typename T >
struct push_coroutine< T & >::control_block { struct push_coroutine< T & >::control_block {
boost::context::captured_context ctx; boost::context::execution_context< T * > ctx;
typename pull_coroutine< T & >::control_block * other; typename pull_coroutine< T & >::control_block * other;
state_t state; state_t state;
std::exception_ptr except; std::exception_ptr except;
@ -60,7 +60,7 @@ struct push_coroutine< T & >::control_block {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
control_block( context::preallocated, StackAllocator, 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( control_block &) = delete;
control_block & operator=( 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 { struct push_coroutine< void >::control_block {
boost::context::captured_context ctx; boost::context::execution_context< void > ctx;
pull_coroutine< void >::control_block * other; pull_coroutine< void >::control_block * other;
state_t state; state_t state;
std::exception_ptr except; std::exception_ptr except;
@ -83,7 +83,7 @@ struct push_coroutine< void >::control_block {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
control_block( context::preallocated, StackAllocator, 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( control_block &) = delete;
control_block & operator=( control_block &) = delete; control_block & operator=( control_block &) = delete;

View File

@ -14,7 +14,7 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/context/captured_context.hpp> #include <boost/context/execution_context.hpp>
#include <boost/coroutine2/detail/config.hpp> #include <boost/coroutine2/detail/config.hpp>
#include <boost/coroutine2/detail/forced_unwind.hpp> #include <boost/coroutine2/detail/forced_unwind.hpp>
@ -32,11 +32,11 @@ namespace detail {
template< typename T > template< typename T >
void void
push_coroutine< T >::control_block::destroy( control_block * cb) noexcept { 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 // destroy control structure
cb->~control_block(); cb->~control_block();
// destroy coroutine's stack // destroy coroutine's stack
ctx(); ctx( nullptr);
} }
template< typename T > template< typename T >
@ -47,13 +47,13 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
ctx{ std::allocator_arg, palloc, salloc, ctx{ std::allocator_arg, palloc, salloc,
std::move( std::move(
std::bind( 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 > // create synthesized pull_coroutine< T >
typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx }; typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx };
pull_coroutine< T > synthesized{ & synthesized_cb }; pull_coroutine< T > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
// set transferred value // set transferred value
synthesized_cb.set( static_cast< T * >( data) ); synthesized_cb.set( data);
try { try {
auto fn = std::move( fn_); auto fn = std::move( fn_);
// call coroutine-fn with synthesized pull_coroutine as argument // 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 // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}, },
@ -76,13 +76,13 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
std::placeholders::_2))}, std::placeholders::_2))},
#else #else
ctx{ std::allocator_arg, palloc, salloc, 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 > // create synthesized pull_coroutine< T >
typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx }; typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx };
pull_coroutine< T > synthesized{ & synthesized_cb }; pull_coroutine< T > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
// set transferred value // set transferred value
synthesized_cb.set( static_cast< T * >( data) ); synthesized_cb.set( data);
try { try {
auto fn = std::move( fn_); auto fn = std::move( fn_);
// call coroutine-fn with synthesized pull_coroutine as argument // 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 // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}}, }},
@ -108,7 +108,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
template< typename T > template< typename T >
push_coroutine< T >::control_block::control_block( typename pull_coroutine< T >::control_block * cb, 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_) }, ctx{ std::move( ctx_) },
other{ cb }, other{ cb },
state{ state_t::none }, state{ state_t::none },
@ -157,11 +157,11 @@ push_coroutine< T >::control_block::valid() const noexcept {
template< typename T > template< typename T >
void void
push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { 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 // destroy control structure
cb->~control_block(); cb->~control_block();
// destroy coroutine's stack // destroy coroutine's stack
ctx(); ctx( nullptr);
} }
template< typename T > template< typename T >
@ -172,13 +172,13 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
ctx{ std::allocator_arg, palloc, salloc, ctx{ std::allocator_arg, palloc, salloc,
std::move( std::move(
std::bind( 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 > // create synthesized pull_coroutine< T & >
typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx }; typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx };
pull_coroutine< T & > synthesized{ & synthesized_cb }; pull_coroutine< T & > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
// set transferred value // set transferred value
synthesized_cb.t = static_cast< T * >( data); synthesized_cb.t = data;
try { try {
auto fn = std::move( fn_); auto fn = std::move( fn_);
// call coroutine-fn with synthesized pull_coroutine as argument // 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 // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}, },
@ -201,13 +201,13 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
std::placeholders::_2))}, std::placeholders::_2))},
#else #else
ctx{ std::allocator_arg, palloc, salloc, 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 > // create synthesized pull_coroutine< T & >
typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx }; typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx };
pull_coroutine< T & > synthesized{ & synthesized_cb }; pull_coroutine< T & > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
// set transferred value // set transferred value
synthesized_cb.t = static_cast< T * >( data); synthesized_cb.t = data;
try { try {
auto fn = std::move( fn_); auto fn = std::move( fn_);
// call coroutine-fn with synthesized pull_coroutine as argument // 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 // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); auto result = other->ctx( nullptr);
other->ctx = std::move( std::get< 0 >( result) ); other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}}, }},
@ -233,7 +233,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
template< typename T > template< typename T >
push_coroutine< T & >::control_block::control_block( typename pull_coroutine< T & >::control_block * cb, 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_) }, ctx{ std::move( ctx_) },
other{ cb }, other{ cb },
state{ state_t::none }, state{ state_t::none },
@ -271,7 +271,7 @@ push_coroutine< T & >::control_block::valid() const noexcept {
inline inline
void void
push_coroutine< void >::control_block::destroy( control_block * cb) noexcept { 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 // destroy control structure
cb->~control_block(); cb->~control_block();
// destroy coroutine's stack // destroy coroutine's stack
@ -284,8 +284,8 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
ctx{ std::allocator_arg, palloc, salloc, ctx{ std::allocator_arg, palloc, salloc,
std::move( std::move(
std::bind( 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< void > ctx) mutable {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< void >
typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx }; typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx };
pull_coroutine< void > synthesized{ & synthesized_cb }; pull_coroutine< void > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
@ -302,17 +302,15 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); other->ctx = other->ctx();
other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}, },
std::forward< Fn >( fn), std::forward< Fn >( fn),
std::placeholders::_1, std::placeholders::_1))},
std::placeholders::_2))},
#else #else
ctx{ std::allocator_arg, palloc, salloc, 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< void > ctx) mutable {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< void >
typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx}; typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx};
pull_coroutine< void > synthesized{ & synthesized_cb }; pull_coroutine< void > synthesized{ & synthesized_cb };
other = & synthesized_cb; other = & synthesized_cb;
@ -329,8 +327,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
// set termination flags // set termination flags
state |= state_t::complete; state |= state_t::complete;
// jump back to ctx // jump back to ctx
auto result = other->ctx(); other->ctx = other->ctx();
other->ctx = std::move( std::get< 0 >( result) );
return std::move( other->ctx); return std::move( other->ctx);
}}, }},
#endif #endif
@ -341,7 +338,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
inline inline
push_coroutine< void >::control_block::control_block( pull_coroutine< void >::control_block * cb, 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_) }, ctx{ std::move( ctx_) },
other{ cb }, other{ cb },
state{ state_t::none }, state{ state_t::none },
@ -359,8 +356,7 @@ push_coroutine< void >::control_block::deallocate() noexcept {
inline inline
void void
push_coroutine< void >::control_block::resume() { push_coroutine< void >::control_block::resume() {
auto result = ctx(); ctx = ctx();
ctx = std::move( std::get< 0 >( result) );
if ( except) { if ( except) {
std::rethrow_exception( except); std::rethrow_exception( except);
} }