mirror of
https://github.com/boostorg/coroutine2.git
synced 2025-05-11 13:34:08 +00:00
move coroutine-function into lambda
This commit is contained in:
parent
2c2524fe8e
commit
57156db7bb
@ -38,12 +38,13 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
|
|||||||
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
std::bind(
|
std::bind(
|
||||||
[this]( typename std::decay< Fn >::type & fn, boost::context::execution_context ctx, void *) mutable noexcept {
|
[this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context ctx, void *) mutable noexcept {
|
||||||
// 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;
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized push_coroutine as argument
|
// call coroutine-fn with synthesized push_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
@ -63,12 +64,13 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
|
|||||||
std::placeholders::_1)},
|
std::placeholders::_1)},
|
||||||
#else
|
#else
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
[this,fn=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
[this,fn_=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
||||||
// 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;
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized push_coroutine as argument
|
// call coroutine-fn with synthesized push_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
@ -169,19 +171,20 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
|
|||||||
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
std::bind(
|
std::bind(
|
||||||
[this]( typename std::decay< Fn >::type & fn, boost::context::execution_context ctx, void *) mutable noexcept {
|
[this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context ctx, void *) mutable noexcept {
|
||||||
// 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;
|
||||||
try {
|
try {
|
||||||
// call coroutine-fn with synthesized push_coroutine as argument
|
auto fn = std::move( fn_);
|
||||||
fn( synthesized);
|
// call coroutine-fn with synthesized push_coroutine as argument
|
||||||
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
// do nothing for unwinding exception
|
// do nothing for unwinding exception
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// store other exceptions in exception-pointer
|
// store other exceptions in exception-pointer
|
||||||
except = std::current_exception();
|
except = std::current_exception();
|
||||||
}
|
}
|
||||||
// set termination flags
|
// set termination flags
|
||||||
state |= state_t::complete;
|
state |= state_t::complete;
|
||||||
@ -194,12 +197,13 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
|
|||||||
std::placeholders::_1)},
|
std::placeholders::_1)},
|
||||||
#else
|
#else
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
[this,fn=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
[this,fn_=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
||||||
// 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;
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized push_coroutine as argument
|
// call coroutine-fn with synthesized push_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
@ -278,19 +282,20 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
|
|||||||
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
std::bind(
|
std::bind(
|
||||||
[this]( typename std::decay< Fn >::type & fn, boost::context::execution_context ctx, void *) mutable noexcept {
|
[this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context ctx, void *) mutable noexcept {
|
||||||
// create synthesized push_coroutine< T >
|
// create synthesized push_coroutine< T >
|
||||||
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;
|
||||||
try {
|
try {
|
||||||
// call coroutine-fn with synthesized push_coroutine as argument
|
auto fn = std::move( fn_);
|
||||||
fn( synthesized);
|
// call coroutine-fn with synthesized push_coroutine as argument
|
||||||
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
// do nothing for unwinding exception
|
// do nothing for unwinding exception
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// store other exceptions in exception-pointer
|
// store other exceptions in exception-pointer
|
||||||
except = std::current_exception();
|
except = std::current_exception();
|
||||||
}
|
}
|
||||||
// set termination flags
|
// set termination flags
|
||||||
state |= state_t::complete;
|
state |= state_t::complete;
|
||||||
@ -303,12 +308,13 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
|
|||||||
std::placeholders::_1)},
|
std::placeholders::_1)},
|
||||||
#else
|
#else
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
[this,fn=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
[this,fn_=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
||||||
// create synthesized push_coroutine< T >
|
// create synthesized push_coroutine< T >
|
||||||
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;
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized push_coroutine as argument
|
// call coroutine-fn with synthesized push_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
|
@ -39,7 +39,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
|
|||||||
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
std::bind(
|
std::bind(
|
||||||
[this]( typename std::decay< Fn >::type & fn, boost::context::execution_context ctx, void * vp) mutable noexcept {
|
[this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context ctx, void * vp) mutable noexcept {
|
||||||
// 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 };
|
||||||
@ -49,13 +49,14 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
|
|||||||
// set transferred value
|
// set transferred value
|
||||||
synthesized_cb.set( t);
|
synthesized_cb.set( t);
|
||||||
try {
|
try {
|
||||||
// call coroutine-fn with synthesized pull_coroutine as argument
|
auto fn = std::move( fn_);
|
||||||
fn( synthesized);
|
// call coroutine-fn with synthesized pull_coroutine as argument
|
||||||
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
// do nothing for unwinding exception
|
// do nothing for unwinding exception
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// store other exceptions in exception-pointer
|
// store other exceptions in exception-pointer
|
||||||
except = std::current_exception();
|
except = std::current_exception();
|
||||||
}
|
}
|
||||||
// set termination flags
|
// set termination flags
|
||||||
state |= state_t::complete;
|
state |= state_t::complete;
|
||||||
@ -68,7 +69,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
|
|||||||
std::placeholders::_1)},
|
std::placeholders::_1)},
|
||||||
#else
|
#else
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
[this,fn=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
[this,fn_=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
||||||
// 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 };
|
||||||
@ -78,6 +79,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
|
|||||||
// set transferred value
|
// set transferred value
|
||||||
synthesized_cb.set( t);
|
synthesized_cb.set( t);
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized pull_coroutine as argument
|
// call coroutine-fn with synthesized pull_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
@ -165,7 +167,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
|
|||||||
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
std::bind(
|
std::bind(
|
||||||
[this]( typename std::decay< Fn >::type & fn, boost::context::execution_context ctx, void * vp) mutable noexcept {
|
[this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context ctx, void * vp) mutable noexcept {
|
||||||
// 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 };
|
||||||
@ -175,13 +177,14 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
|
|||||||
// set transferred value
|
// set transferred value
|
||||||
synthesized_cb.t = t;
|
synthesized_cb.t = t;
|
||||||
try {
|
try {
|
||||||
// call coroutine-fn with synthesized pull_coroutine as argument
|
auto fn = std::move( fn_);
|
||||||
fn( synthesized);
|
// call coroutine-fn with synthesized pull_coroutine as argument
|
||||||
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
// do nothing for unwinding exception
|
// do nothing for unwinding exception
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// store other exceptions in exception-pointer
|
// store other exceptions in exception-pointer
|
||||||
except = std::current_exception();
|
except = std::current_exception();
|
||||||
}
|
}
|
||||||
// set termination flags
|
// set termination flags
|
||||||
state |= state_t::complete;
|
state |= state_t::complete;
|
||||||
@ -194,7 +197,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
|
|||||||
std::placeholders::_1)},
|
std::placeholders::_1)},
|
||||||
#else
|
#else
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
[this,fn=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
[this,fn_=std::forward< Fn >( fn),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
||||||
// 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 };
|
||||||
@ -204,6 +207,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
|
|||||||
// set transferred value
|
// set transferred value
|
||||||
synthesized_cb.t = t;
|
synthesized_cb.t = t;
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized pull_coroutine as argument
|
// call coroutine-fn with synthesized pull_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
@ -274,7 +278,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
|
|||||||
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
std::bind(
|
std::bind(
|
||||||
[this]( typename std::decay< Fn >::type & fn, boost::context::execution_context ctx,
|
[this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context ctx,
|
||||||
void * vp) mutable noexcept {
|
void * vp) mutable noexcept {
|
||||||
// create synthesized pull_coroutine< T >
|
// create synthesized pull_coroutine< T >
|
||||||
typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx };
|
typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx };
|
||||||
@ -283,6 +287,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
|
|||||||
// jump back to ctor
|
// jump back to ctor
|
||||||
ctx();
|
ctx();
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized pull_coroutine as argument
|
// call coroutine-fn with synthesized pull_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
@ -302,7 +307,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
|
|||||||
std::placeholders::_1)},
|
std::placeholders::_1)},
|
||||||
#else
|
#else
|
||||||
ctx{ std::allocator_arg, palloc, salloc,
|
ctx{ std::allocator_arg, palloc, salloc,
|
||||||
[this,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
[this,fn_=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] (void *) mutable noexcept {
|
||||||
// create synthesized pull_coroutine< T >
|
// create synthesized pull_coroutine< T >
|
||||||
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 };
|
||||||
@ -310,6 +315,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
|
|||||||
// jump back to ctor
|
// jump back to ctor
|
||||||
ctx();
|
ctx();
|
||||||
try {
|
try {
|
||||||
|
auto fn = std::move( fn_);
|
||||||
// call coroutine-fn with synthesized pull_coroutine as argument
|
// call coroutine-fn with synthesized pull_coroutine as argument
|
||||||
fn( synthesized);
|
fn( synthesized);
|
||||||
} catch ( forced_unwind const&) {
|
} catch ( forced_unwind const&) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user