diff options
Diffstat (limited to 'boost/coroutine2/detail')
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_cc.hpp | 14 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_cc.ipp | 252 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_coroutine.hpp | 33 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_coroutine.ipp | 12 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_control_block_cc.hpp | 14 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_control_block_cc.ipp | 245 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_coroutine.hpp | 25 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_coroutine.ipp | 12 | ||||
-rw-r--r-- | boost/coroutine2/detail/wrap.hpp | 8 |
9 files changed, 313 insertions, 302 deletions
diff --git a/boost/coroutine2/detail/pull_control_block_cc.hpp b/boost/coroutine2/detail/pull_control_block_cc.hpp index b9ac614109..da60cc482a 100644 --- a/boost/coroutine2/detail/pull_control_block_cc.hpp +++ b/boost/coroutine2/detail/pull_control_block_cc.hpp @@ -11,7 +11,7 @@ #include <type_traits> #include <boost/config.hpp> -#include <boost/context/continuation.hpp> +#include <boost/context/fiber.hpp> #include <boost/coroutine2/detail/state.hpp> @@ -25,7 +25,7 @@ namespace detail { template< typename T > struct pull_coroutine< T >::control_block { - boost::context::continuation c; + boost::context::fiber c; typename push_coroutine< T >::control_block * other; state_t state; std::exception_ptr except; @@ -37,7 +37,7 @@ struct pull_coroutine< T >::control_block { template< typename StackAllocator, typename 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::fiber &) noexcept; ~control_block(); @@ -66,7 +66,7 @@ struct pull_coroutine< T & >::control_block { } }; - boost::context::continuation c; + boost::context::fiber c; typename push_coroutine< T & >::control_block * other; state_t state; std::exception_ptr except; @@ -78,7 +78,7 @@ struct pull_coroutine< T & >::control_block { template< typename StackAllocator, typename 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::fiber &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; @@ -95,7 +95,7 @@ struct pull_coroutine< T & >::control_block { }; struct pull_coroutine< void >::control_block { - boost::context::continuation c; + boost::context::fiber c; push_coroutine< void >::control_block * other; state_t state; std::exception_ptr except; @@ -105,7 +105,7 @@ struct pull_coroutine< void >::control_block { template< typename StackAllocator, typename 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::fiber &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; 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); } diff --git a/boost/coroutine2/detail/pull_coroutine.hpp b/boost/coroutine2/detail/pull_coroutine.hpp index 32cd68eb70..c8ea49f367 100644 --- a/boost/coroutine2/detail/pull_coroutine.hpp +++ b/boost/coroutine2/detail/pull_coroutine.hpp @@ -56,8 +56,7 @@ public: pull_coroutine & operator=( pull_coroutine && other) noexcept { if ( this == & other) return * this; - cb_ = other.cb_; - other.cb_ = nullptr; + std::swap( cb_, other.cb_); return * this; } @@ -69,7 +68,7 @@ public: T get() noexcept; - class iterator : public std::iterator< std::input_iterator_tag, typename std::remove_reference< T >::type > { + class iterator { private: pull_coroutine< T > * c_{ nullptr }; @@ -89,8 +88,14 @@ public: } public: - typedef typename iterator::pointer pointer_t; - typedef typename iterator::reference reference_t; + typedef std::input_iterator_tag iterator_category; + typedef typename std::remove_reference< T >::type value_type; + typedef std::ptrdiff_t difference_type; + typedef value_type * pointer; + typedef value_type & reference; + + typedef pointer pointer_t; + typedef reference reference_t; iterator() noexcept = default; @@ -168,8 +173,7 @@ public: pull_coroutine & operator=( pull_coroutine && other) noexcept { if ( this == & other) return * this; - cb_ = other.cb_; - other.cb_ = nullptr; + std::swap( cb_, other.cb_); return * this; } @@ -181,7 +185,7 @@ public: T & get() noexcept; - class iterator : public std::iterator< std::input_iterator_tag, typename std::remove_reference< T >::type > { + class iterator { private: pull_coroutine< T & > * c_{ nullptr }; @@ -201,8 +205,14 @@ public: } public: - typedef typename iterator::pointer pointer_t; - typedef typename iterator::reference reference_t; + typedef std::input_iterator_tag iterator_category; + typedef typename std::remove_reference< T >::type value_type; + typedef std::ptrdiff_t difference_type; + typedef value_type * pointer; + typedef value_type & reference; + + typedef pointer pointer_t; + typedef reference reference_t; iterator() noexcept = default; @@ -278,8 +288,7 @@ public: pull_coroutine & operator=( pull_coroutine && other) noexcept { if ( this == & other) return * this; - cb_ = other.cb_; - other.cb_ = nullptr; + std::swap( cb_, other.cb_); return * this; } diff --git a/boost/coroutine2/detail/pull_coroutine.ipp b/boost/coroutine2/detail/pull_coroutine.ipp index 699d5ab9a2..6a2f6ed768 100644 --- a/boost/coroutine2/detail/pull_coroutine.ipp +++ b/boost/coroutine2/detail/pull_coroutine.ipp @@ -67,8 +67,8 @@ pull_coroutine< T >::~pull_coroutine() { template< typename T > pull_coroutine< T >::pull_coroutine( pull_coroutine && other) noexcept : - cb_{ other.cb_ } { - other.cb_ = nullptr; + cb_{ nullptr } { + std::swap( cb_, other.cb_); } template< typename T > @@ -136,8 +136,8 @@ pull_coroutine< T & >::~pull_coroutine() { template< typename T > pull_coroutine< T & >::pull_coroutine( pull_coroutine && other) noexcept : - cb_{ other.cb_ } { - other.cb_ = nullptr; + cb_{ nullptr } { + std::swap( cb_, other.cb_); } template< typename T > @@ -197,8 +197,8 @@ pull_coroutine< void >::~pull_coroutine() { inline pull_coroutine< void >::pull_coroutine( pull_coroutine && other) noexcept : - cb_{ other.cb_ } { - other.cb_ = nullptr; + cb_{ nullptr } { + std::swap( cb_, other.cb_); } inline diff --git a/boost/coroutine2/detail/push_control_block_cc.hpp b/boost/coroutine2/detail/push_control_block_cc.hpp index 8dda44fb7e..1c32a0e6e5 100644 --- a/boost/coroutine2/detail/push_control_block_cc.hpp +++ b/boost/coroutine2/detail/push_control_block_cc.hpp @@ -10,7 +10,7 @@ #include <exception> #include <boost/config.hpp> -#include <boost/context/continuation.hpp> +#include <boost/context/fiber.hpp> #include <boost/coroutine2/detail/state.hpp> @@ -24,7 +24,7 @@ namespace detail { template< typename T > struct push_coroutine< T >::control_block { - boost::context::continuation c; + boost::context::fiber c; typename pull_coroutine< T >::control_block * other; state_t state; std::exception_ptr except; @@ -34,7 +34,7 @@ struct push_coroutine< T >::control_block { template< typename StackAllocator, typename 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::fiber &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; @@ -50,7 +50,7 @@ struct push_coroutine< T >::control_block { template< typename T > struct push_coroutine< T & >::control_block { - boost::context::continuation c; + boost::context::fiber c; typename pull_coroutine< T & >::control_block * other; state_t state; std::exception_ptr except; @@ -60,7 +60,7 @@ struct push_coroutine< T & >::control_block { template< typename StackAllocator, typename 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::fiber &) noexcept; control_block( 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 { - boost::context::continuation c; + boost::context::fiber c; pull_coroutine< void >::control_block * other; state_t state; std::exception_ptr except; @@ -83,7 +83,7 @@ struct push_coroutine< void >::control_block { template< typename StackAllocator, typename 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::fiber &) noexcept; control_block( control_block &) = delete; control_block & operator=( control_block &) = delete; 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); } diff --git a/boost/coroutine2/detail/push_coroutine.hpp b/boost/coroutine2/detail/push_coroutine.hpp index d152be2cde..4b5ba5c25d 100644 --- a/boost/coroutine2/detail/push_coroutine.hpp +++ b/boost/coroutine2/detail/push_coroutine.hpp @@ -54,8 +54,7 @@ public: push_coroutine & operator=( push_coroutine && other) noexcept { if ( this == & other) return * this; - cb_ = other.cb_; - other.cb_ = nullptr; + std::swap( cb_, other.cb_); return * this; } @@ -67,11 +66,17 @@ public: bool operator!() const noexcept; - class iterator : public std::iterator< std::output_iterator_tag, void, void, void, void > { + class iterator { private: push_coroutine< T > * c_{ nullptr }; public: + typedef std::output_iterator_tag iterator_category; + typedef void value_type; + typedef void difference_type; + typedef void pointer; + typedef void reference; + iterator() noexcept = default; explicit iterator( push_coroutine< T > * c) noexcept : @@ -134,8 +139,7 @@ public: push_coroutine & operator=( push_coroutine && other) noexcept { if ( this == & other) return * this; - cb_ = other.cb_; - other.cb_ = nullptr; + std::swap( cb_, other.cb_); return * this; } @@ -145,11 +149,17 @@ public: bool operator!() const noexcept; - class iterator : public std::iterator< std::output_iterator_tag, void, void, void, void > { + class iterator { private: push_coroutine< T & > * c_{ nullptr }; public: + typedef std::output_iterator_tag iterator_category; + typedef void value_type; + typedef void difference_type; + typedef void pointer; + typedef void reference; + iterator() noexcept = default; explicit iterator( push_coroutine< T & > * c) noexcept : @@ -212,8 +222,7 @@ public: push_coroutine & operator=( push_coroutine && other) noexcept { if ( this == & other) return * this; - cb_ = other.cb_; - other.cb_ = nullptr; + std::swap( cb_, other.cb_); return * this; } diff --git a/boost/coroutine2/detail/push_coroutine.ipp b/boost/coroutine2/detail/push_coroutine.ipp index dd51403d9b..dedfa42429 100644 --- a/boost/coroutine2/detail/push_coroutine.ipp +++ b/boost/coroutine2/detail/push_coroutine.ipp @@ -56,8 +56,8 @@ push_coroutine< T >::~push_coroutine() { template< typename T > push_coroutine< T >::push_coroutine( push_coroutine && other) noexcept : - cb_{ other.cb_ } { - other.cb_ = nullptr; + cb_{ nullptr } { + std::swap( cb_, other.cb_); } template< typename T > @@ -116,8 +116,8 @@ push_coroutine< T & >::~push_coroutine() { template< typename T > push_coroutine< T & >::push_coroutine( push_coroutine && other) noexcept : - cb_{ other.cb_ } { - other.cb_ = nullptr; + cb_{ nullptr } { + std::swap( cb_, other.cb_); } template< typename T > @@ -167,8 +167,8 @@ push_coroutine< void >::~push_coroutine() { inline push_coroutine< void >::push_coroutine( push_coroutine && other) noexcept : - cb_{ other.cb_ } { - other.cb_ = nullptr; + cb_{ nullptr } { + std::swap( cb_, other.cb_); } inline diff --git a/boost/coroutine2/detail/wrap.hpp b/boost/coroutine2/detail/wrap.hpp index cd56338484..87809f01b9 100644 --- a/boost/coroutine2/detail/wrap.hpp +++ b/boost/coroutine2/detail/wrap.hpp @@ -11,7 +11,7 @@ #include <boost/config.hpp> #include <boost/context/detail/invoke.hpp> -#include <boost/context/continuation.hpp> +#include <boost/context/fiber.hpp> #include <boost/coroutine2/detail/config.hpp> @@ -41,12 +41,12 @@ public: wrapper( wrapper && other) = default; wrapper & operator=( wrapper && other) = default; - boost::context::continuation - operator()( boost::context::continuation && c) { + boost::context::fiber + operator()( boost::context::fiber && c) { return boost::context::detail::invoke( std::move( fn1_), fn2_, - std::forward< boost::context::continuation >( c) ); + std::forward< boost::context::fiber >( c) ); } }; |