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/pull_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/pull_control_block_cc.ipp')
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_cc.ipp | 252 |
1 files changed, 123 insertions, 129 deletions
diff --git a/boost/coroutine2/detail/pull_control_block_cc.ipp b/boost/coroutine2/detail/pull_control_block_cc.ipp index 43fdb76f9b..c156b632a6 100644 --- a/boost/coroutine2/detail/pull_control_block_cc.ipp +++ b/boost/coroutine2/detail/pull_control_block_cc.ipp @@ -15,7 +15,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> @@ -34,7 +34,7 @@ namespace detail { template< typename T > void pull_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 @@ -45,42 +45,9 @@ template< typename T > template< typename StackAllocator, typename Fn > pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc, Fn && fn) : - c{}, - other{ nullptr }, - state{ state_t::unwind }, - except{}, - bvalid{ false }, - storage{} { #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 push_coroutine< T > - typename push_coroutine< T >::control_block synthesized_cb{ this, c }; - push_coroutine< T > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - auto fn = std::move( fn_); - // call coroutine-fn with synthesized push_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 push_coroutine< T > typename push_coroutine< T >::control_block synthesized_cb{ this, c }; push_coroutine< T > synthesized{ & synthesized_cb }; @@ -100,17 +67,48 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, // set termination flags state |= state_t::complete; // jump back - return other->c.resume(); - }); + return std::move( other->c).resume(); + }, + 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 push_coroutine< T > + typename push_coroutine< T >::control_block synthesized_cb{ this, c }; + push_coroutine< T > synthesized{ & synthesized_cb }; + other = & synthesized_cb; + if ( state_t::none == ( state & state_t::destroy) ) { + try { + auto fn = std::move( fn_); + // call coroutine-fn with synthesized push_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 - if ( except) { - std::rethrow_exception( except); - } + other{ nullptr }, + state{ state_t::unwind }, + except{}, + bvalid{ false }, + storage{} { + c = std::move( c).resume(); + if ( except) { + std::rethrow_exception( except); + } } template< typename T > pull_coroutine< T >::control_block::control_block( typename push_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 }, @@ -138,7 +136,7 @@ pull_coroutine< T >::control_block::deallocate() noexcept { template< typename T > void pull_coroutine< T >::control_block::resume() { - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } @@ -184,7 +182,7 @@ pull_coroutine< T >::control_block::valid() const noexcept { template< typename T > void pull_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 @@ -195,42 +193,9 @@ template< typename T > template< typename StackAllocator, typename Fn > pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator && salloc, Fn && fn) : - c{}, - other{ nullptr }, - state{ state_t::unwind }, - except{}, - bvalid{ false }, - storage{} { #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 push_coroutine< T & > - typename push_coroutine< T & >::control_block synthesized_cb{ this, c }; - push_coroutine< T & > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - auto fn = std::move( fn_); - // call coroutine-fn with synthesized push_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 push_coroutine< T & > typename push_coroutine< T & >::control_block synthesized_cb{ this, c }; push_coroutine< T & > synthesized{ & synthesized_cb }; @@ -250,17 +215,48 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo // set termination flags state |= state_t::complete; // jump back - return other->c.resume(); - }); + return std::move( other->c).resume(); + }, + 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 push_coroutine< T & > + typename push_coroutine< T & >::control_block synthesized_cb{ this, c }; + push_coroutine< T & > synthesized{ & synthesized_cb }; + other = & synthesized_cb; + if ( state_t::none == ( state & state_t::destroy) ) { + try { + auto fn = std::move( fn_); + // call coroutine-fn with synthesized push_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 - if ( except) { - std::rethrow_exception( except); - } + other{ nullptr }, + state{ state_t::unwind }, + except{}, + bvalid{ false }, + storage{} { + c = std::move( c).resume(); + if ( except) { + std::rethrow_exception( except); + } } template< typename T > pull_coroutine< T & >::control_block::control_block( typename push_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 }, @@ -280,7 +276,7 @@ pull_coroutine< T & >::control_block::deallocate() noexcept { template< typename T > void pull_coroutine< T & >::control_block::resume() { - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } @@ -311,7 +307,7 @@ pull_coroutine< T & >::control_block::valid() const noexcept { inline void pull_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 @@ -321,40 +317,9 @@ pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept { template< typename StackAllocator, typename Fn > pull_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 push_coroutine< void > - typename push_coroutine< void >::control_block synthesized_cb{ this, c }; - push_coroutine< void > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - auto fn = std::move( fn_); - // call coroutine-fn with synthesized push_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 push_coroutine< void > typename push_coroutine< void >::control_block synthesized_cb{ this, c }; push_coroutine< void > synthesized{ & synthesized_cb }; @@ -373,18 +338,47 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall } // set termination flags state |= state_t::complete; - // jump back to ctx - return other->c.resume(); - }); + // jump back + return std::move( other->c).resume(); + }, + 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 push_coroutine< void > + typename push_coroutine< void >::control_block synthesized_cb{ this, c }; + push_coroutine< void > synthesized{ & synthesized_cb }; + other = & synthesized_cb; + if ( state_t::none == ( state & state_t::destroy) ) { + try { + auto fn = std::move( fn_); + // call coroutine-fn with synthesized push_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 to ctx + return std::move( other->c).resume(); + } }, #endif - if ( except) { - std::rethrow_exception( except); - } + other{ nullptr }, + state{ state_t::unwind }, + except{} { + c = std::move( c).resume(); + if ( except) { + std::rethrow_exception( except); + } } inline pull_coroutine< void >::control_block::control_block( push_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 }, @@ -402,7 +396,7 @@ pull_coroutine< void >::control_block::deallocate() noexcept { inline void pull_coroutine< void >::control_block::resume() { - c = c.resume(); + c = std::move( c).resume(); if ( except) { std::rethrow_exception( except); } |