perfect forwarding of stack allocator

This commit is contained in:
Oliver Kowalke 2017-09-24 09:04:20 +02:00
parent 6317f864cb
commit 40cbfe5c01
9 changed files with 44 additions and 44 deletions

View File

@ -28,7 +28,7 @@ namespace coroutines2 {
namespace detail { namespace detail {
template< typename ControlBlock, typename StackAllocator, typename Fn > template< typename ControlBlock, typename StackAllocator, typename Fn >
ControlBlock * create_control_block( StackAllocator salloc, Fn && fn) { ControlBlock * create_control_block( StackAllocator && salloc, Fn && fn) {
auto sctx = salloc.allocate(); auto sctx = salloc.allocate();
// reserve space for control structure // reserve space for control structure
#if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_NO_CXX11_STD_ALIGN) #if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_NO_CXX11_STD_ALIGN)
@ -48,7 +48,7 @@ ControlBlock * create_control_block( StackAllocator salloc, Fn && fn) {
#endif #endif
// placment new for control structure on coroutine stack // placment new for control structure on coroutine stack
return new ( sp) ControlBlock{ context::preallocated( sp, size, sctx), return new ( sp) ControlBlock{ context::preallocated( sp, size, sctx),
salloc, std::forward< Fn >( fn) }; std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) };
} }
}}} }}}

View File

@ -35,7 +35,7 @@ struct pull_coroutine< T >::control_block {
static void destroy( control_block * cb) noexcept; static void destroy( control_block * cb) noexcept;
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::continuation &) noexcept; control_block( typename push_coroutine< T >::control_block *, boost::context::continuation &) noexcept;
@ -76,7 +76,7 @@ struct pull_coroutine< T & >::control_block {
static void destroy( control_block * cb) noexcept; static void destroy( control_block * cb) noexcept;
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::continuation &) noexcept; control_block( typename push_coroutine< T & >::control_block *, boost::context::continuation &) noexcept;
@ -103,7 +103,7 @@ struct pull_coroutine< void >::control_block {
static void destroy( control_block * cb) noexcept; static void destroy( control_block * cb) noexcept;
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::continuation &) noexcept; control_block( push_coroutine< void >::control_block *, boost::context::continuation &) noexcept;

View File

@ -43,7 +43,7 @@ pull_coroutine< T >::control_block::destroy( control_block * cb) noexcept {
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc,
Fn && fn) : Fn && fn) :
c{}, c{},
other{ nullptr }, other{ nullptr },
@ -53,7 +53,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
storage{} { storage{} {
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< T >
typename push_coroutine< T >::control_block synthesized_cb{ this, c }; typename push_coroutine< T >::control_block synthesized_cb{ this, c };
@ -79,7 +79,7 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc,
std::forward< Fn >( fn) ) ); std::forward< Fn >( fn) ) );
#else #else
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
[this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< T >
typename push_coroutine< T >::control_block synthesized_cb{ this, c }; typename push_coroutine< T >::control_block synthesized_cb{ this, c };
@ -193,7 +193,7 @@ pull_coroutine< T & >::control_block::destroy( control_block * cb) noexcept {
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc,
Fn && fn) : Fn && fn) :
c{}, c{},
other{ nullptr }, other{ nullptr },
@ -203,7 +203,7 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
storage{} { storage{} {
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable {
// create synthesized push_coroutine< T & > // create synthesized push_coroutine< T & >
typename push_coroutine< T & >::control_block synthesized_cb{ this, c }; typename push_coroutine< T & >::control_block synthesized_cb{ this, c };
@ -229,7 +229,7 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo
std::forward< Fn >( fn) ) ); std::forward< Fn >( fn) ) );
#else #else
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
[this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable {
// create synthesized push_coroutine< T & > // create synthesized push_coroutine< T & >
typename push_coroutine< T & >::control_block synthesized_cb{ this, c }; typename push_coroutine< T & >::control_block synthesized_cb{ this, c };
@ -319,7 +319,7 @@ pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept {
} }
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, pull_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc,
Fn && fn) : Fn && fn) :
c{}, c{},
other{ nullptr }, other{ nullptr },
@ -327,7 +327,7 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
except{} { except{} {
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable {
// create synthesized push_coroutine< void > // create synthesized push_coroutine< void >
typename push_coroutine< void >::control_block synthesized_cb{ this, c }; typename push_coroutine< void >::control_block synthesized_cb{ this, c };
@ -353,7 +353,7 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall
std::forward< Fn >( fn) ) ); std::forward< Fn >( fn) ) );
#else #else
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
[this,fn_=std::forward< Fn >( fn)]( boost::context::continuation && c) mutable { [this,fn_=std::forward< Fn >( fn)]( boost::context::continuation && c) mutable {
// create synthesized push_coroutine< void > // create synthesized push_coroutine< void >
typename push_coroutine< void >::control_block synthesized_cb{ this, c }; typename push_coroutine< void >::control_block synthesized_cb{ this, c };

View File

@ -45,7 +45,7 @@ public:
explicit pull_coroutine( Fn &&); explicit pull_coroutine( Fn &&);
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine( StackAllocator, Fn &&); pull_coroutine( StackAllocator &&, Fn &&);
~pull_coroutine(); ~pull_coroutine();
@ -157,7 +157,7 @@ public:
explicit pull_coroutine( Fn &&); explicit pull_coroutine( Fn &&);
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine( StackAllocator, Fn &&); pull_coroutine( StackAllocator &&, Fn &&);
~pull_coroutine(); ~pull_coroutine();
@ -267,7 +267,7 @@ public:
explicit pull_coroutine( Fn &&); explicit pull_coroutine( Fn &&);
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine( StackAllocator, Fn &&); pull_coroutine( StackAllocator &&, Fn &&);
~pull_coroutine(); ~pull_coroutine();

View File

@ -50,8 +50,8 @@ pull_coroutine< T >::pull_coroutine( Fn && fn) :
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine< T >::pull_coroutine( StackAllocator salloc, Fn && fn) : pull_coroutine< T >::pull_coroutine( StackAllocator && salloc, Fn && fn) :
cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } { cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
if ( ! cb_->valid() ) { if ( ! cb_->valid() ) {
cb_->deallocate(); cb_->deallocate();
cb_ = nullptr; cb_ = nullptr;
@ -119,8 +119,8 @@ pull_coroutine< T & >::pull_coroutine( Fn && fn) :
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine< T & >::pull_coroutine( StackAllocator salloc, Fn && fn) : pull_coroutine< T & >::pull_coroutine( StackAllocator && salloc, Fn && fn) :
cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } { cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
if ( ! cb_->valid() ) { if ( ! cb_->valid() ) {
cb_->deallocate(); cb_->deallocate();
cb_ = nullptr; cb_ = nullptr;
@ -180,8 +180,8 @@ pull_coroutine< void >::pull_coroutine( Fn && fn) :
} }
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
pull_coroutine< void >::pull_coroutine( StackAllocator salloc, Fn && fn) : pull_coroutine< void >::pull_coroutine( StackAllocator && salloc, Fn && fn) :
cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } { cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
if ( ! cb_->valid() ) { if ( ! cb_->valid() ) {
cb_->deallocate(); cb_->deallocate();
cb_ = nullptr; cb_ = nullptr;

View File

@ -32,7 +32,7 @@ struct push_coroutine< T >::control_block {
static void destroy( control_block * cb) noexcept; static void destroy( control_block * cb) noexcept;
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::continuation &) noexcept; control_block( typename pull_coroutine< T >::control_block *, boost::context::continuation &) noexcept;
@ -58,7 +58,7 @@ struct push_coroutine< T & >::control_block {
static void destroy( control_block * cb) noexcept; static void destroy( control_block * cb) noexcept;
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::continuation &) noexcept; control_block( typename pull_coroutine< T & >::control_block *, boost::context::continuation &) noexcept;
@ -81,7 +81,7 @@ struct push_coroutine< void >::control_block {
static void destroy( control_block * cb) noexcept; static void destroy( control_block * cb) noexcept;
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::continuation &) noexcept; control_block( pull_coroutine< void >::control_block *, boost::context::continuation &) noexcept;

View File

@ -42,7 +42,7 @@ push_coroutine< T >::control_block::destroy( control_block * cb) noexcept {
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc,
Fn && fn) : Fn && fn) :
c{}, c{},
other{ nullptr }, other{ nullptr },
@ -50,7 +50,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
except{} { except{} {
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< T >
typename pull_coroutine< T >::control_block synthesized_cb{ this, c }; typename pull_coroutine< T >::control_block synthesized_cb{ this, c };
@ -77,7 +77,7 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc,
std::forward< Fn >( fn) ) ); std::forward< Fn >( fn) ) );
#else #else
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
[this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< T >
typename pull_coroutine< T >::control_block synthesized_cb{ this, c }; typename pull_coroutine< T >::control_block synthesized_cb{ this, c };
@ -166,7 +166,7 @@ push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept {
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc,
Fn && fn) : Fn && fn) :
c{}, c{},
other{ nullptr }, other{ nullptr },
@ -174,7 +174,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
except{} { except{} {
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable {
// create synthesized pull_coroutine< T & > // create synthesized pull_coroutine< T & >
typename pull_coroutine< T & >::control_block synthesized_cb{ this, c }; typename pull_coroutine< T & >::control_block synthesized_cb{ this, c };
@ -201,7 +201,7 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo
std::forward< Fn >( fn) ) ); std::forward< Fn >( fn) ) );
#else #else
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
[this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable {
// create synthesized pull_coroutine< T & > // create synthesized pull_coroutine< T & >
typename pull_coroutine< T & >::control_block synthesized_cb{ this, c }; typename pull_coroutine< T & >::control_block synthesized_cb{ this, c };
@ -277,14 +277,14 @@ push_coroutine< void >::control_block::destroy( control_block * cb) noexcept {
} }
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, Fn && fn) : push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc, Fn && fn) :
c{}, c{},
other{ nullptr }, other{ nullptr },
state{ state_t::unwind }, state{ state_t::unwind },
except{} { except{} {
#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable {
// create synthesized pull_coroutine< void > // create synthesized pull_coroutine< void >
typename pull_coroutine< void >::control_block synthesized_cb{ this, c }; typename pull_coroutine< void >::control_block synthesized_cb{ this, c };
@ -311,7 +311,7 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall
std::forward< Fn >( fn) ) ); std::forward< Fn >( fn) ) );
#else #else
c = boost::context::callcc( c = boost::context::callcc(
std::allocator_arg, palloc, salloc, std::allocator_arg, palloc, std::forward< StackAllocator >( salloc),
[this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable {
// create synthesized pull_coroutine< void > // create synthesized pull_coroutine< void >
typename pull_coroutine< void >::control_block synthesized_cb{ this, c}; typename pull_coroutine< void >::control_block synthesized_cb{ this, c};

View File

@ -43,7 +43,7 @@ public:
explicit push_coroutine( Fn &&); explicit push_coroutine( Fn &&);
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine( StackAllocator, Fn &&); push_coroutine( StackAllocator &&, Fn &&);
~push_coroutine(); ~push_coroutine();
@ -123,7 +123,7 @@ public:
explicit push_coroutine( Fn &&); explicit push_coroutine( Fn &&);
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine( StackAllocator, Fn &&); push_coroutine( StackAllocator &&, Fn &&);
~push_coroutine(); ~push_coroutine();
@ -201,7 +201,7 @@ public:
explicit push_coroutine( Fn &&); explicit push_coroutine( Fn &&);
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine( StackAllocator, Fn &&); push_coroutine( StackAllocator &&, Fn &&);
~push_coroutine(); ~push_coroutine();

View File

@ -43,8 +43,8 @@ push_coroutine< T >::push_coroutine( Fn && fn) :
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< T >::push_coroutine( StackAllocator salloc, Fn && fn) : push_coroutine< T >::push_coroutine( StackAllocator && salloc, Fn && fn) :
cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } { cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
} }
template< typename T > template< typename T >
@ -103,8 +103,8 @@ push_coroutine< T & >::push_coroutine( Fn && fn) :
template< typename T > template< typename T >
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< T & >::push_coroutine( StackAllocator salloc, Fn && fn) : push_coroutine< T & >::push_coroutine( StackAllocator && salloc, Fn && fn) :
cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } { cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
} }
template< typename T > template< typename T >
@ -154,8 +154,8 @@ push_coroutine< void >::push_coroutine( Fn && fn) :
} }
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< void >::push_coroutine( StackAllocator salloc, Fn && fn) : push_coroutine< void >::push_coroutine( StackAllocator && salloc, Fn && fn) :
cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } { cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
} }
inline inline