diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
commit | b8cf34c691623e4ec329053cbbf68522a855882d (patch) | |
tree | 34da08632a99677f6b79ecb65e5b655a5b69a67f /boost/coroutine2/detail/push_control_block_cc.ipp | |
parent | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (diff) | |
download | boost-b8cf34c691623e4ec329053cbbf68522a855882d.tar.gz boost-b8cf34c691623e4ec329053cbbf68522a855882d.tar.bz2 boost-b8cf34c691623e4ec329053cbbf68522a855882d.zip |
Imported Upstream version 1.67.0upstream/1.67.0
Diffstat (limited to 'boost/coroutine2/detail/push_control_block_cc.ipp')
-rw-r--r-- | boost/coroutine2/detail/push_control_block_cc.ipp | 245 |
1 files changed, 122 insertions, 123 deletions
diff --git a/boost/coroutine2/detail/push_control_block_cc.ipp b/boost/coroutine2/detail/push_control_block_cc.ipp index ae7dee1f7a..a7c0be341f 100644 --- a/boost/coroutine2/detail/push_control_block_cc.ipp +++ b/boost/coroutine2/detail/push_control_block_cc.ipp @@ -14,7 +14,7 @@ #include <boost/assert.hpp> #include <boost/config.hpp> -#include <boost/context/continuation.hpp> +#include <boost/context/fiber.hpp> #include <boost/coroutine2/detail/config.hpp> #include <boost/coroutine2/detail/forced_unwind.hpp> @@ -33,7 +33,7 @@ namespace detail { template< typename T > void push_coroutine< T >::control_block::destroy( control_block * cb) noexcept { - boost::context::continuation c = std::move( cb->c); + boost::context::fiber c = std::move( cb->c); // destroy control structure cb->~control_block(); // destroy coroutine's stack @@ -44,46 +44,14 @@ template< typename T > template< typename StackAllocator, typename Fn > push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc, Fn && fn) : - c{}, - other{ nullptr }, - state{ state_t::unwind }, - except{} { #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - c = boost::context::callcc( - std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), - wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { - // create synthesized pull_coroutine< T > - typename pull_coroutine< T >::control_block synthesized_cb{ this, c }; - pull_coroutine< T > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - other->c = other->c.resume(); - if ( state_t::none == ( state & state_t::destroy) ) { - try { - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( boost::context::detail::forced_unwind const&) { - throw; - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back - return other->c.resume(); - }, - std::forward< Fn >( fn) ) ); -#else - c = boost::context::callcc( - std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), - [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { + c{ std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), + wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::fiber && c) mutable { // create synthesized pull_coroutine< T > typename pull_coroutine< T >::control_block synthesized_cb{ this, c }; pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; - other->c = other->c.resume(); + other->c = std::move( other->c).resume(); if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -99,14 +67,45 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, // set termination flags state |= state_t::complete; // jump back - return other->c.resume(); - }); + other->c = std::move( other->c).resume(); + return std::move( other->c); + }, + std::forward< Fn >( fn) ) }, +#else + c{ std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), + [this,fn_=std::forward< Fn >( fn)](boost::context::fiber && c) mutable { + // create synthesized pull_coroutine< T > + typename pull_coroutine< T >::control_block synthesized_cb{ this, c }; + pull_coroutine< T > synthesized{ & synthesized_cb }; + other = & synthesized_cb; + other->c = std::move( other->c).resume(); + if ( state_t::none == ( state & state_t::destroy) ) { + try { + auto fn = std::move( fn_); + // call coroutine-fn with synthesized pull_coroutine as argument + fn( synthesized); + } catch ( boost::context::detail::forced_unwind const&) { + throw; + } catch (...) { + // store other exceptions in exception-pointer + except = std::current_exception(); + } + } + // set termination flags + state |= state_t::complete; + // jump back + return std::move( other->c).resume(); + } }, #endif + other{ nullptr }, + state{ state_t::unwind }, + except{} { + c = std::move( c).resume(); } template< typename T > push_coroutine< T >::control_block::control_block( typename pull_coroutine< T >::control_block * cb, - boost::context::continuation & c_) noexcept : + boost::context::fiber & c_) noexcept : c{ std::move( c_) }, other{ cb }, state{ state_t::none }, @@ -127,7 +126,7 @@ push_coroutine< T >::control_block::resume( T const& data) { // pass data to other context other->set( data); // resume other context - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } @@ -139,7 +138,7 @@ push_coroutine< T >::control_block::resume( T && data) { // pass data to other context other->set( std::move( data) ); // resume other context - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } @@ -157,7 +156,7 @@ push_coroutine< T >::control_block::valid() const noexcept { template< typename T > void push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { - boost::context::continuation c = std::move( cb->c); + boost::context::fiber c = std::move( cb->c); // destroy control structure cb->~control_block(); // destroy coroutine's stack @@ -168,46 +167,14 @@ template< typename T > template< typename StackAllocator, typename Fn > push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc, Fn && fn) : - c{}, - other{ nullptr }, - state{ state_t::unwind }, - except{} { #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - c = boost::context::callcc( - std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), - wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { - // create synthesized pull_coroutine< T & > - typename pull_coroutine< T & >::control_block synthesized_cb{ this, c }; - pull_coroutine< T & > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - other->c = other->c.resume(); - if ( state_t::none == ( state & state_t::destroy) ) { - try { - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( boost::context::detail::forced_unwind const&) { - throw; - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back - return other->c.resume(); - }, - std::forward< Fn >( fn) ) ); -#else - c = boost::context::callcc( - std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), - [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { + c{ std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), + wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::fiber && c) mutable { // create synthesized pull_coroutine< T & > typename pull_coroutine< T & >::control_block synthesized_cb{ this, c }; pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; - other->c = other->c.resume(); + other->c = std::move( other->c).resume(); if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -223,14 +190,46 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo // set termination flags state |= state_t::complete; // jump back - return other->c.resume(); - }); + other->c = std::move( other->c).resume(); + return std::move( other->c); + }, + std::forward< Fn >( fn) ) }, +#else + c{ std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), + [this,fn_=std::forward< Fn >( fn)](boost::context::fiber && c) mutable { + // create synthesized pull_coroutine< T & > + typename pull_coroutine< T & >::control_block synthesized_cb{ this, c }; + pull_coroutine< T & > synthesized{ & synthesized_cb }; + other = & synthesized_cb; + other->c = std::move( other->c).resume(); + if ( state_t::none == ( state & state_t::destroy) ) { + try { + auto fn = std::move( fn_); + // call coroutine-fn with synthesized pull_coroutine as argument + fn( synthesized); + } catch ( boost::context::detail::forced_unwind const&) { + throw; + } catch (...) { + // store other exceptions in exception-pointer + except = std::current_exception(); + } + } + // set termination flags + state |= state_t::complete; + // jump back + other->c = std::move( other->c).resume(); + return std::move( other->c); + } }, #endif + other{ nullptr }, + state{ state_t::unwind }, + except{} { + c = std::move( c).resume(); } template< typename T > push_coroutine< T & >::control_block::control_block( typename pull_coroutine< T & >::control_block * cb, - boost::context::continuation & c_) noexcept : + boost::context::fiber & c_) noexcept : c{ std::move( c_) }, other{ cb }, state{ state_t::none }, @@ -251,7 +250,7 @@ push_coroutine< T & >::control_block::resume( T & data) { // pass data to other context other->set( data); // resume other context - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } @@ -269,7 +268,7 @@ push_coroutine< T & >::control_block::valid() const noexcept { inline void push_coroutine< void >::control_block::destroy( control_block * cb) noexcept { - boost::context::continuation c = std::move( cb->c); + boost::context::fiber c = std::move( cb->c); // destroy control structure cb->~control_block(); // destroy coroutine's stack @@ -278,46 +277,14 @@ push_coroutine< void >::control_block::destroy( control_block * cb) noexcept { template< typename StackAllocator, typename Fn > push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc, Fn && fn) : - c{}, - other{ nullptr }, - state{ state_t::unwind }, - except{} { #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - c = boost::context::callcc( - std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), - wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::continuation && c) mutable { - // create synthesized pull_coroutine< void > - typename pull_coroutine< void >::control_block synthesized_cb{ this, c }; - pull_coroutine< void > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - other->c = other->c.resume(); - if ( state_t::none == ( state & state_t::destroy) ) { - try { - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( boost::context::detail::forced_unwind const&) { - throw; - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back - return other->c.resume(); - }, - std::forward< Fn >( fn) ) ); -#else - c = boost::context::callcc( - std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), - [this,fn_=std::forward< Fn >( fn)](boost::context::continuation && c) mutable { + c{ std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), + wrap( [this](typename std::decay< Fn >::type & fn_,boost::context::fiber && c) mutable { // 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 }; pull_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; - other->c = other->c.resume(); + other->c = std::move( other->c).resume(); if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -333,14 +300,46 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall // set termination flags state |= state_t::complete; // jump back - return other->c.resume(); - }); + other->c = std::move( other->c).resume(); + return std::move( other->c); + }, + std::forward< Fn >( fn) ) }, +#else + c{ std::allocator_arg, palloc, std::forward< StackAllocator >( salloc), + [this,fn_=std::forward< Fn >( fn)](boost::context::fiber && c) mutable { + // create synthesized pull_coroutine< void > + typename pull_coroutine< void >::control_block synthesized_cb{ this, c}; + pull_coroutine< void > synthesized{ & synthesized_cb }; + other = & synthesized_cb; + other->c = std::move( other->c).resume(); + if ( state_t::none == ( state & state_t::destroy) ) { + try { + auto fn = std::move( fn_); + // call coroutine-fn with synthesized pull_coroutine as argument + fn( synthesized); + } catch ( boost::context::detail::forced_unwind const&) { + throw; + } catch (...) { + // store other exceptions in exception-pointer + except = std::current_exception(); + } + } + // set termination flags + state |= state_t::complete; + // jump back + other->c = std::move( other->c).resume(); + return std::move( other->c); + } }, #endif + other{ nullptr }, + state{ state_t::unwind }, + except{} { + c = std::move( c).resume(); } inline push_coroutine< void >::control_block::control_block( pull_coroutine< void >::control_block * cb, - boost::context::continuation & c_) noexcept : + boost::context::fiber & c_) noexcept : c{ std::move( c_) }, other{ cb }, state{ state_t::none }, @@ -358,7 +357,7 @@ push_coroutine< void >::control_block::deallocate() noexcept { inline void push_coroutine< void >::control_block::resume() { - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } |