diff options
Diffstat (limited to 'boost/coroutine2/detail')
-rw-r--r-- | boost/coroutine2/detail/config.hpp | 8 | ||||
-rw-r--r-- | boost/coroutine2/detail/coroutine.hpp | 28 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_cc.hpp | 2 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_cc.ipp | 38 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_ecv1.hpp | 119 | ||||
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_ecv1.ipp | 431 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_control_block_cc.ipp | 47 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_control_block_ecv1.hpp | 111 | ||||
-rw-r--r-- | boost/coroutine2/detail/push_control_block_ecv1.ipp | 428 | ||||
-rw-r--r-- | boost/coroutine2/detail/wrap.hpp | 49 |
10 files changed, 23 insertions, 1238 deletions
diff --git a/boost/coroutine2/detail/config.hpp b/boost/coroutine2/detail/config.hpp index 307ee4e78a..e725213a91 100644 --- a/boost/coroutine2/detail/config.hpp +++ b/boost/coroutine2/detail/config.hpp @@ -27,12 +27,4 @@ # define BOOST_COROUTINES2_DECL #endif -#if ! defined(BOOST_COROUTINES2_SOURCE) && ! defined(BOOST_ALL_NO_LIB) && ! defined(BOOST_COROUTINES2_NO_LIB) -# define BOOST_LIB_NAME boost_coroutine2 -# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_COROUTINES2_DYN_LINK) -# define BOOST_DYN_LINK -# endif -# include <boost/config/auto_link.hpp> -#endif - #endif // BOOST_COROUTINES2_DETAIL_CONFIG_H diff --git a/boost/coroutine2/detail/coroutine.hpp b/boost/coroutine2/detail/coroutine.hpp index 1170590183..c52608b163 100644 --- a/boost/coroutine2/detail/coroutine.hpp +++ b/boost/coroutine2/detail/coroutine.hpp @@ -29,26 +29,14 @@ class push_coroutine; #include <boost/coroutine2/detail/pull_coroutine.hpp> #include <boost/coroutine2/detail/push_coroutine.hpp> -#if defined(BOOST_EXECUTION_CONTEXT) -# if (BOOST_EXECUTION_CONTEXT==1) -# include <boost/coroutine2/detail/pull_control_block_ecv1.hpp> -# include <boost/coroutine2/detail/push_control_block_ecv1.hpp> -# else -# include <boost/coroutine2/detail/pull_control_block_cc.hpp> -# include <boost/coroutine2/detail/push_control_block_cc.hpp> -# endif - -# include <boost/coroutine2/detail/pull_coroutine.ipp> -# include <boost/coroutine2/detail/push_coroutine.ipp> - -# if (BOOST_EXECUTION_CONTEXT==1) -# include <boost/coroutine2/detail/pull_control_block_ecv1.ipp> -# include <boost/coroutine2/detail/push_control_block_ecv1.ipp> -# else -# include <boost/coroutine2/detail/pull_control_block_cc.ipp> -# include <boost/coroutine2/detail/push_control_block_cc.ipp> -# endif -#endif +#include <boost/coroutine2/detail/pull_control_block_cc.hpp> +#include <boost/coroutine2/detail/push_control_block_cc.hpp> + +#include <boost/coroutine2/detail/pull_coroutine.ipp> +#include <boost/coroutine2/detail/push_coroutine.ipp> + +#include <boost/coroutine2/detail/pull_control_block_cc.ipp> +#include <boost/coroutine2/detail/push_control_block_cc.ipp> #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/boost/coroutine2/detail/pull_control_block_cc.hpp b/boost/coroutine2/detail/pull_control_block_cc.hpp index 44a14e2102..5353fb8be1 100644 --- a/boost/coroutine2/detail/pull_control_block_cc.hpp +++ b/boost/coroutine2/detail/pull_control_block_cc.hpp @@ -50,7 +50,6 @@ struct pull_coroutine< T >::control_block { void set( T const&); void set( T &&); - void reset(); T & get() noexcept; @@ -89,7 +88,6 @@ struct pull_coroutine< T & >::control_block { void resume(); void set( T &); - void reset(); T & get() noexcept; diff --git a/boost/coroutine2/detail/pull_control_block_cc.ipp b/boost/coroutine2/detail/pull_control_block_cc.ipp index 0406202016..486833455e 100644 --- a/boost/coroutine2/detail/pull_control_block_cc.ipp +++ b/boost/coroutine2/detail/pull_control_block_cc.ipp @@ -39,7 +39,6 @@ pull_coroutine< T >::control_block::destroy( control_block * cb) noexcept { cb->~control_block(); // destroy coroutine's stack cb->state |= state_t::destroy; - c.resume(); } template< typename T > @@ -104,9 +103,6 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, return other->c.resume(); }); #endif - if ( c.data_available() ) { - set( c.get_data< T >() ); - } } template< typename T > @@ -140,11 +136,6 @@ template< typename T > void pull_coroutine< T >::control_block::resume() { c = c.resume(); - if ( c.data_available() ) { - set( c.get_data< T >() ); - } else { - reset(); - } if ( except) { std::rethrow_exception( except); } @@ -173,16 +164,6 @@ pull_coroutine< T >::control_block::set( T && t) { } template< typename T > -void -pull_coroutine< T >::control_block::reset() { - // destroy data if set - if ( bvalid) { - reinterpret_cast< T * >( std::addressof( storage) )->~T(); - } - bvalid = false; -} - -template< typename T > T & pull_coroutine< T >::control_block::get() noexcept { return * reinterpret_cast< T * >( std::addressof( storage) ); @@ -205,7 +186,6 @@ pull_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { cb->~control_block(); // destroy coroutine's stack cb->state |= state_t::destroy; - c.resume(); } template< typename T > @@ -270,9 +250,6 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo return other->c.resume(); }); #endif - if ( c.data_available() ) { - set( c.get_data< T & >() ); - } } template< typename T > @@ -298,11 +275,6 @@ template< typename T > void pull_coroutine< T & >::control_block::resume() { c = c.resume(); - if ( c.data_available() ) { - set( c.get_data< T & >() ); - } else { - reset(); - } if ( except) { std::rethrow_exception( except); } @@ -316,15 +288,6 @@ pull_coroutine< T & >::control_block::set( T & t) { } template< typename T > -void -pull_coroutine< T & >::control_block::reset() { - if ( bvalid) { - reinterpret_cast< holder * >( std::addressof( storage) )->~holder(); - } - bvalid = false; -} - -template< typename T > T & pull_coroutine< T & >::control_block::get() noexcept { return reinterpret_cast< holder * >( std::addressof( storage) )->t; @@ -347,7 +310,6 @@ pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept { cb->~control_block(); // destroy coroutine's stack cb->state |= state_t::destroy; - c.resume(); } template< typename StackAllocator, typename Fn > diff --git a/boost/coroutine2/detail/pull_control_block_ecv1.hpp b/boost/coroutine2/detail/pull_control_block_ecv1.hpp deleted file mode 100644 index 16d65a3e62..0000000000 --- a/boost/coroutine2/detail/pull_control_block_ecv1.hpp +++ /dev/null @@ -1,119 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP -#define BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP - -#include <exception> -#include <functional> -#include <type_traits> - -#include <boost/config.hpp> -#include <boost/context/execution_context.hpp> - -#include <boost/coroutine2/detail/state.hpp> - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace coroutines2 { -namespace detail { - -template< typename T > -struct pull_coroutine< T >::control_block { - boost::context::execution_context ctx; - typename push_coroutine< T >::control_block * other; - state_t state; - std::exception_ptr except; - bool bvalid; - typename std::aligned_storage< sizeof( T), alignof( T) >::type storage; - - static void destroy( control_block * cb) noexcept; - - template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, Fn &&); - - control_block( typename push_coroutine< T >::control_block *, boost::context::execution_context const&) noexcept; - - ~control_block() noexcept; - - control_block( control_block &) = delete; - control_block & operator=( control_block &) = delete; - - void deallocate() noexcept; - - void resume(); - - void set( T *); - - T & get() noexcept; - - bool valid() const noexcept; -}; - -template< typename T > -struct pull_coroutine< T & >::control_block { - boost::context::execution_context ctx; - typename push_coroutine< T & >::control_block * other; - state_t state; - std::exception_ptr except; - T * t; - - static void destroy( control_block * cb) noexcept; - - template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, Fn &&); - - control_block( typename push_coroutine< T & >::control_block *, boost::context::execution_context const&) noexcept; - - ~control_block() noexcept; - - control_block( control_block &) = delete; - control_block & operator=( control_block &) = delete; - - void deallocate() noexcept; - - void resume(); - - T & get() noexcept; - - bool valid() const noexcept; -}; - -struct pull_coroutine< void >::control_block { - boost::context::execution_context ctx; - push_coroutine< void >::control_block * other; - state_t state; - std::exception_ptr except; - - static void destroy( control_block * cb) noexcept; - - template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, Fn &&); - - control_block( push_coroutine< void >::control_block *, boost::context::execution_context const&) noexcept; - - ~control_block() noexcept; - - control_block( control_block &) = delete; - control_block & operator=( control_block &) = delete; - - void deallocate() noexcept; - - void resume(); - - bool valid() const noexcept; -}; - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP diff --git a/boost/coroutine2/detail/pull_control_block_ecv1.ipp b/boost/coroutine2/detail/pull_control_block_ecv1.ipp deleted file mode 100644 index 77866041fe..0000000000 --- a/boost/coroutine2/detail/pull_control_block_ecv1.ipp +++ /dev/null @@ -1,431 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_IPP -#define BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_IPP - -#include <exception> -#include <functional> -#include <memory> - -#include <boost/assert.hpp> -#include <boost/config.hpp> - -#include <boost/context/execution_context.hpp> - -#include <boost/coroutine2/detail/config.hpp> -#include <boost/coroutine2/detail/decay_copy.hpp> -#include <boost/coroutine2/detail/forced_unwind.hpp> -#include <boost/coroutine2/detail/state.hpp> -#include <boost/coroutine2/detail/wrap.hpp> - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace coroutines2 { -namespace detail { - -// pull_coroutine< T > - -template< typename T > -void -pull_coroutine< T >::control_block::destroy( control_block * cb) noexcept { - boost::context::execution_context ctx = cb->ctx; - // destroy control structure - cb->state |= state_t::destroy; - cb->~control_block(); -} - -template< typename T > -template< typename StackAllocator, typename Fn > -pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - Fn && fn) : -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx{ std::allocator_arg, palloc, salloc, - wrap( [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context & ctx, void *) mutable noexcept { - // create synthesized push_coroutine< T > - typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; - 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 ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); - }, - std::forward< Fn >( fn), - boost::context::execution_context::current() ) }, -#else - ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=decay_copy( std::forward< Fn >( fn) ),ctx=boost::context::execution_context::current()] (void *) mutable noexcept { - // create synthesized push_coroutine< T > - typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; - 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 ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); - }}, -#endif - other{ nullptr }, - state{ state_t::unwind }, - except{}, - bvalid{ false }, - storage{} { - // enter coroutine-fn in order to have first value available after ctor (of `*this`) returns - set( static_cast< T * >( ctx() ) ); -} - -template< typename T > -pull_coroutine< T >::control_block::control_block( typename push_coroutine< T >::control_block * cb, - boost::context::execution_context const& ctx_) noexcept : - ctx{ ctx_ }, - other{ cb }, - state{ state_t::none }, - except{}, - bvalid{ false }, - storage{} { -} - -template< typename T > -pull_coroutine< T >::control_block::~control_block() { - if ( state_t::none == ( state & state_t::complete) && - state_t::none != ( state & state_t::unwind) ) { - // unwind coroutine stack - other->ctx = boost::context::execution_context::current(); - ctx( context::exec_ontop_arg, unwind_coroutine); - } - // destroy data if it set - if ( bvalid) { - reinterpret_cast< T * >( std::addressof( storage) )->~T(); - } -} - -template< typename T > -void -pull_coroutine< T >::control_block::deallocate() noexcept { - if ( state_t::none != ( state & state_t::unwind) ) { - destroy( this); - } -} - -template< typename T > -void -pull_coroutine< T >::control_block::resume() { - other->ctx = boost::context::execution_context::current(); - set( static_cast< T * >( ctx() ) ); - if ( except) { - std::rethrow_exception( except); - } -} - -template< typename T > -void -pull_coroutine< T >::control_block::set( T * t) { - // destroy data if it set - if ( bvalid) { - reinterpret_cast< T * >( std::addressof( storage) )->~T(); - } - if ( nullptr != t) { - ::new ( static_cast< void * >( std::addressof( storage) ) ) T( std::move( * t) ); - bvalid = true; - } else { - bvalid = false; - } -} - -template< typename T > -T & -pull_coroutine< T >::control_block::get() noexcept { - return * reinterpret_cast< T * >( std::addressof( storage) ); -} - -template< typename T > -bool -pull_coroutine< T >::control_block::valid() const noexcept { - return nullptr != other && state_t::none == ( state & state_t::complete) && bvalid; -} - - -// pull_coroutine< T & > - -template< typename T > -void -pull_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { - boost::context::execution_context ctx = cb->ctx; - // destroy control structure - cb->state |= state_t::destroy; - cb->~control_block(); -} - -template< typename T > -template< typename StackAllocator, typename Fn > -pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - Fn && fn) : -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx{ std::allocator_arg, palloc, salloc, - wrap( [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context & ctx, void *) mutable noexcept { - // create synthesized push_coroutine< T > - typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; - 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 ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); - }, - std::forward< Fn >( fn), - boost::context::execution_context::current() ) }, -#else - ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=decay_copy( std::forward< Fn >( fn) ),ctx=boost::context::execution_context::current()] (void *) mutable noexcept { - // create synthesized push_coroutine< T > - typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; - 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 ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); - }}, -#endif - other{ nullptr }, - state{ state_t::unwind }, - except{}, - t{ nullptr } { - // enter coroutine-fn in order to have first value available after ctor (of `*this`) returns - t = static_cast< T * >( ctx() ); -} - -template< typename T > -pull_coroutine< T & >::control_block::control_block( typename push_coroutine< T & >::control_block * cb, - boost::context::execution_context const& ctx_) noexcept : - ctx{ ctx_ }, - other{ cb }, - state{ state_t::none }, - except{}, - t( nullptr) { -} - -template< typename T > -pull_coroutine< T & >::control_block::~control_block() { - if ( state_t::none == ( state & state_t::complete) && - state_t::none != ( state & state_t::unwind) ) { - // unwind coroutine stack - other->ctx = boost::context::execution_context::current(); - ctx( context::exec_ontop_arg, unwind_coroutine); - } -} - -template< typename T > -void -pull_coroutine< T & >::control_block::deallocate() noexcept { - if ( state_t::none != ( state & state_t::unwind) ) { - destroy( this); - } -} - -template< typename T > -void -pull_coroutine< T & >::control_block::resume() { - other->ctx = boost::context::execution_context::current(); - t = static_cast< T * >( ctx() ); - if ( except) { - std::rethrow_exception( except); - } -} - -template< typename T > -T & -pull_coroutine< T & >::control_block::get() noexcept { - return * static_cast< T * >( t); -} - -template< typename T > -bool -pull_coroutine< T & >::control_block::valid() const noexcept { - return nullptr != other && state_t::none == ( state & state_t::complete) && nullptr != t; -} - - -// pull_coroutine< void > - -inline -void -pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept { - boost::context::execution_context ctx = cb->ctx; - // destroy control structure - cb->state |= state_t::destroy; - cb->~control_block(); -} - -template< typename StackAllocator, typename Fn > -pull_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - Fn && fn) : -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx{ std::allocator_arg, palloc, salloc, - wrap( [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context & ctx, void *) mutable noexcept { - // create synthesized push_coroutine< T > - typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; - 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 ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); - }, - std::forward< Fn >( fn), - boost::context::execution_context::current() ) }, -#else - ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=decay_copy( std::forward< Fn >( fn) ),ctx=boost::context::execution_context::current()] (void *) mutable noexcept { - // create synthesized push_coroutine< T > - typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; - 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 ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); - }}, -#endif - other{ nullptr }, - state{ state_t::unwind }, - except{} { - // enter coroutine-fn in order to have first value available after ctor returns - ctx(); -} - -inline -pull_coroutine< void >::control_block::control_block( push_coroutine< void >::control_block * cb, - boost::context::execution_context const& ctx_) noexcept : - ctx{ ctx_ }, - other{ cb }, - state{ state_t::none }, - except{} { -} - -inline -pull_coroutine< void >::control_block::~control_block() { - if ( state_t::none == ( state & state_t::complete) && - state_t::none != ( state & state_t::unwind) ) { - // unwind coroutine stack - other->ctx = boost::context::execution_context::current(); - ctx( context::exec_ontop_arg, unwind_coroutine); - } -} - -inline -void -pull_coroutine< void >::control_block::deallocate() noexcept { - if ( state_t::none != ( state & state_t::unwind) ) { - destroy( this); - } -} - -inline -void -pull_coroutine< void >::control_block::resume() { - other->ctx = boost::context::execution_context::current(); - ctx(); - if ( except) { - std::rethrow_exception( except); - } -} - -inline -bool -pull_coroutine< void >::control_block::valid() const noexcept { - return nullptr != other && state_t::none == ( state & state_t::complete); -} - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_IPP diff --git a/boost/coroutine2/detail/push_control_block_cc.ipp b/boost/coroutine2/detail/push_control_block_cc.ipp index 9972c7039f..98b24f2642 100644 --- a/boost/coroutine2/detail/push_control_block_cc.ipp +++ b/boost/coroutine2/detail/push_control_block_cc.ipp @@ -38,7 +38,6 @@ push_coroutine< T >::control_block::destroy( control_block * cb) noexcept { cb->~control_block(); // destroy coroutine's stack cb->state |= state_t::destroy; - c.resume(); } template< typename T > @@ -58,12 +57,6 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -91,12 +84,6 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -137,8 +124,10 @@ push_coroutine< T >::control_block::deallocate() noexcept { template< typename T > void push_coroutine< T >::control_block::resume( T const& data) { - // pass an pointer to other context - c = c.resume( data); + // pass data to other context + other->set( data); + // resume other context + c = c.resume(); if ( except) { std::rethrow_exception( except); } @@ -147,8 +136,10 @@ push_coroutine< T >::control_block::resume( T const& data) { template< typename T > void push_coroutine< T >::control_block::resume( T && data) { - // pass an pointer to other context - c = c.resume( std::move( data) ); + // pass data to other context + other->set( std::move( data) ); + // resume other context + c = c.resume(); if ( except) { std::rethrow_exception( except); } @@ -171,7 +162,6 @@ push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { cb->~control_block(); // destroy coroutine's stack cb->state |= state_t::destroy; - c.resume(); } template< typename T > @@ -191,12 +181,6 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T & >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -224,12 +208,6 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T & >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -269,9 +247,11 @@ push_coroutine< T & >::control_block::deallocate() noexcept { template< typename T > void -push_coroutine< T & >::control_block::resume( T & t) { - // pass an pointer to other context - c = c.resume( std::ref( t) ); +push_coroutine< T & >::control_block::resume( T & data) { + // pass data to other context + other->set( data); + // resume other context + c = c.resume(); if ( except) { std::rethrow_exception( except); } @@ -294,7 +274,6 @@ push_coroutine< void >::control_block::destroy( control_block * cb) noexcept { cb->~control_block(); // destroy coroutine's stack cb->state |= state_t::destroy; - c.resume(); } template< typename StackAllocator, typename Fn > diff --git a/boost/coroutine2/detail/push_control_block_ecv1.hpp b/boost/coroutine2/detail/push_control_block_ecv1.hpp deleted file mode 100644 index 29d49716a7..0000000000 --- a/boost/coroutine2/detail/push_control_block_ecv1.hpp +++ /dev/null @@ -1,111 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_COROUTINES2_DETAIL_PUSH_CONTROL_BLOCK_HPP -#define BOOST_COROUTINES2_DETAIL_PUSH_CONTROL_BLOCK_HPP - -#include <functional> -#include <exception> - -#include <boost/config.hpp> -#include <boost/context/execution_context.hpp> - -#include <boost/coroutine2/detail/state.hpp> - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace coroutines2 { -namespace detail { - -template< typename T > -struct push_coroutine< T >::control_block { - boost::context::execution_context ctx; - typename pull_coroutine< T >::control_block * other; - state_t state; - std::exception_ptr except; - - static void destroy( control_block * cb) noexcept; - - template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, Fn &&); - - control_block( typename pull_coroutine< T >::control_block *, boost::context::execution_context const&) noexcept; - - ~control_block() noexcept; - - control_block( control_block &) = delete; - control_block & operator=( control_block &) = delete; - - void deallocate() noexcept; - - void resume( T const&); - - void resume( T &&); - - bool valid() const noexcept; -}; - -template< typename T > -struct push_coroutine< T & >::control_block { - boost::context::execution_context ctx; - typename pull_coroutine< T & >::control_block * other; - state_t state; - std::exception_ptr except; - - static void destroy( control_block * cb) noexcept; - - template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, Fn &&); - - control_block( typename pull_coroutine< T & >::control_block *, boost::context::execution_context const&) noexcept; - - ~control_block() noexcept; - - control_block( control_block &) = delete; - control_block & operator=( control_block &) = delete; - - void deallocate() noexcept; - - void resume( T &); - - bool valid() const noexcept; -}; - -struct push_coroutine< void >::control_block { - boost::context::execution_context ctx; - pull_coroutine< void >::control_block * other; - state_t state; - std::exception_ptr except; - - static void destroy( control_block * cb) noexcept; - - template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, Fn &&); - - control_block( pull_coroutine< void >::control_block *, boost::context::execution_context const&) noexcept; - - ~control_block() noexcept; - - control_block( control_block &) = delete; - control_block & operator=( control_block &) = delete; - - void deallocate() noexcept; - - void resume(); - - bool valid() const noexcept; -}; - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_COROUTINES2_DETAIL_PUSH_CONTROL_BLOCK_HPP diff --git a/boost/coroutine2/detail/push_control_block_ecv1.ipp b/boost/coroutine2/detail/push_control_block_ecv1.ipp deleted file mode 100644 index 8b4ae3fb04..0000000000 --- a/boost/coroutine2/detail/push_control_block_ecv1.ipp +++ /dev/null @@ -1,428 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_COROUTINES2_DETAIL_PUSH_CONTROL_BLOCK_IPP -#define BOOST_COROUTINES2_DETAIL_PUSH_CONTROL_BLOCK_IPP - -#include <algorithm> -#include <exception> -#include <functional> -#include <memory> - -#include <boost/assert.hpp> -#include <boost/config.hpp> - -#include <boost/context/execution_context.hpp> - -#include <boost/coroutine2/detail/config.hpp> -#include <boost/coroutine2/detail/decay_copy.hpp> -#include <boost/coroutine2/detail/forced_unwind.hpp> -#include <boost/coroutine2/detail/state.hpp> -#include <boost/coroutine2/detail/wrap.hpp> - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace coroutines2 { -namespace detail { - -// push_coroutine< T > - -template< typename T > -void -push_coroutine< T >::control_block::destroy( control_block * cb) noexcept { - boost::context::execution_context ctx = cb->ctx; - // destroy control structure - cb->state |= state_t::destroy; - cb->~control_block(); -} - -template< typename T > -template< typename StackAllocator, typename Fn > -push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - Fn && fn) : -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx{ std::allocator_arg, palloc, salloc, - wrap( [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context & ctx, void * vp) mutable noexcept { - // create synthesized pull_coroutine< T > - typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx }; - pull_coroutine< T > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - // jump back to ctor - T * t = static_cast< T * >( ctx() ); - // set transferred value - synthesized_cb.set( t); - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "push_coroutine is complete"); - }, - std::forward< Fn >( fn), - boost::context::execution_context::current() ) }, -#else - ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=decay_copy( std::forward< Fn >( fn) ),ctx=boost::context::execution_context::current()] (void *) mutable noexcept { - // create synthesized pull_coroutine< T > - typename pull_coroutine< T >::control_block synthesized_cb{ this, ctx }; - pull_coroutine< T > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - // jump back to ctor - T * t = static_cast< T * >( ctx() ); - // set transferred value - synthesized_cb.set( t); - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "push_coroutine is complete"); - }}, -#endif - other{ nullptr }, - state{ state_t::unwind }, - except{} { - // enter coroutine-fn in order to get other set - ctx(); -} - -template< typename T > -push_coroutine< T >::control_block::control_block( typename pull_coroutine< T >::control_block * cb, - boost::context::execution_context const& ctx_) noexcept : - ctx{ ctx_ }, - other{ cb }, - state{ state_t::none }, - except{} { -} - -template< typename T > -push_coroutine< T >::control_block::~control_block() { - if ( state_t::none == ( state & state_t::complete) && - state_t::none != ( state & state_t::unwind) ) { - // unwind coroutine stack - other->ctx = boost::context::execution_context::current(); - ctx( context::exec_ontop_arg, unwind_coroutine); - } -} - -template< typename T > -void -push_coroutine< T >::control_block::deallocate() noexcept { - if ( state_t::none != ( state & state_t::unwind) ) { - destroy( this); - } -} - -template< typename T > -void -push_coroutine< T >::control_block::resume( T const& t) { - other->ctx = boost::context::execution_context::current(); - // pass an pointer to other context - ctx( const_cast< T * >( & t) ); - if ( except) { - std::rethrow_exception( except); - } -} - -template< typename T > -void -push_coroutine< T >::control_block::resume( T && t) { - other->ctx = boost::context::execution_context::current(); - // pass an pointer to other context - ctx( std::addressof( t) ); - if ( except) { - std::rethrow_exception( except); - } -} - -template< typename T > -bool -push_coroutine< T >::control_block::valid() const noexcept { - return state_t::none == ( state & state_t::complete ); -} - - -// push_coroutine< T & > - -template< typename T > -void -push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept { - boost::context::execution_context ctx = cb->ctx; - // destroy control structure - cb->state |= state_t::destroy; - cb->~control_block(); -} - -template< typename T > -template< typename StackAllocator, typename Fn > -push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - Fn && fn) : -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx{ std::allocator_arg, palloc, salloc, - wrap( [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context & ctx, void * vp) mutable noexcept { - // create synthesized pull_coroutine< T > - typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx }; - pull_coroutine< T & > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - // jump back to ctor - T * t = static_cast< T * >( ctx() ); - // set transferred value - synthesized_cb.t = t; - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "push_coroutine is complete"); - }, - std::forward< Fn >( fn), - boost::context::execution_context::current() ) }, -#else - ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=decay_copy( std::forward< Fn >( fn) ),ctx=boost::context::execution_context::current()] (void *) mutable noexcept { - // create synthesized pull_coroutine< T > - typename pull_coroutine< T & >::control_block synthesized_cb{ this, ctx }; - pull_coroutine< T & > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - // jump back to ctor - T * t = static_cast< T * >( ctx() ); - // set transferred value - synthesized_cb.t = t; - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "push_coroutine is complete"); - }}, -#endif - other{ nullptr }, - state{ state_t::unwind }, - except{} { - // enter coroutine-fn in order to get other set - ctx(); -} - -template< typename T > -push_coroutine< T & >::control_block::control_block( typename pull_coroutine< T & >::control_block * cb, - boost::context::execution_context const& ctx_) noexcept : - ctx{ ctx_ }, - other{ cb }, - state{ state_t::none }, - except{} { -} - -template< typename T > -push_coroutine< T & >::control_block::~control_block() { - if ( state_t::none == ( state & state_t::complete) && - state_t::none != ( state & state_t::unwind) ) { - // unwind coroutine stack - other->ctx = boost::context::execution_context::current(); - ctx( context::exec_ontop_arg, unwind_coroutine); - } -} - -template< typename T > -void -push_coroutine< T & >::control_block::deallocate() noexcept { - if ( state_t::none != ( state & state_t::unwind) ) { - destroy( this); - } -} - -template< typename T > -void -push_coroutine< T & >::control_block::resume( T & t) { - other->ctx = boost::context::execution_context::current(); - // pass an pointer to other context - ctx( const_cast< typename std::remove_const< T >::type * >( std::addressof( t) ) ); - if ( except) { - std::rethrow_exception( except); - } -} - -template< typename T > -bool -push_coroutine< T & >::control_block::valid() const noexcept { - return state_t::none == ( state & state_t::complete ); -} - - -// push_coroutine< void > - -inline -void -push_coroutine< void >::control_block::destroy( control_block * cb) noexcept { - boost::context::execution_context ctx = cb->ctx; - // destroy control structure - cb->state |= state_t::destroy; - cb->~control_block(); -} - -template< typename StackAllocator, typename Fn > -push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, Fn && fn) : -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx{ std::allocator_arg, palloc, salloc, - wrap( [this]( typename std::decay< Fn >::type & fn_, boost::context::execution_context & ctx, - void * vp) mutable noexcept { - // create synthesized pull_coroutine< T > - typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx }; - pull_coroutine< void > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - // jump back to ctor - ctx(); - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "push_coroutine is complete"); - }, - std::forward< Fn >( fn), - boost::context::execution_context::current() ) }, -#else - ctx{ std::allocator_arg, palloc, salloc, - [this,fn_=decay_copy( std::forward< Fn >( fn) ),ctx=boost::context::execution_context::current()] (void *) mutable noexcept { - // create synthesized pull_coroutine< T > - typename pull_coroutine< void >::control_block synthesized_cb{ this, ctx }; - pull_coroutine< void > synthesized{ & synthesized_cb }; - other = & synthesized_cb; - if ( state_t::none == ( state & state_t::destroy) ) { - try { - // jump back to ctor - ctx(); - auto fn = std::move( fn_); - // call coroutine-fn with synthesized pull_coroutine as argument - fn( synthesized); - } catch ( forced_unwind const&) { - // do nothing for unwinding exception - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - } - // set termination flags - state |= state_t::complete; - // jump back to ctx - other->ctx(); - BOOST_ASSERT_MSG( false, "push_coroutine is complete"); - }}, -#endif - other{ nullptr }, - state{ state_t::unwind }, - except{} { - // enter coroutine-fn in order to get other set - ctx(); -} - -inline -push_coroutine< void >::control_block::control_block( pull_coroutine< void >::control_block * cb, - boost::context::execution_context const& ctx_) noexcept : - ctx{ ctx_ }, - other{ cb }, - state{ state_t::none }, - except{} { -} - -inline -push_coroutine< void >::control_block::~control_block() { - if ( state_t::none == ( state & state_t::complete) && - state_t::none != ( state & state_t::unwind) ) { - // unwind coroutine stack - other->ctx = boost::context::execution_context::current(); - ctx( context::exec_ontop_arg, unwind_coroutine); - } -} - -inline -void -push_coroutine< void >::control_block::deallocate() noexcept { - if ( state_t::none != ( state & state_t::unwind) ) { - destroy( this); - } -} - -inline -void -push_coroutine< void >::control_block::resume() { - other->ctx = boost::context::execution_context::current(); - ctx(); - if ( except) { - std::rethrow_exception( except); - } -} - -inline -bool -push_coroutine< void >::control_block::valid() const noexcept { - return state_t::none == ( state & state_t::complete ); -} - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_COROUTINES2_DETAIL_PUSH_CONTROL_BLOCK_IPP diff --git a/boost/coroutine2/detail/wrap.hpp b/boost/coroutine2/detail/wrap.hpp index 25abce3b61..cd56338484 100644 --- a/boost/coroutine2/detail/wrap.hpp +++ b/boost/coroutine2/detail/wrap.hpp @@ -11,14 +11,9 @@ #include <boost/config.hpp> #include <boost/context/detail/invoke.hpp> -#if (BOOST_EXECUTION_CONTEXT==1) -# include <boost/context/execution_context.hpp> -#else -# include <boost/context/continuation.hpp> -#endif +#include <boost/context/continuation.hpp> -#include <boost/fiber/detail/config.hpp> -#include <boost/fiber/detail/data.hpp> +#include <boost/coroutine2/detail/config.hpp> #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -28,45 +23,6 @@ namespace boost { namespace coroutines2 { namespace detail { -#if (BOOST_EXECUTION_CONTEXT==1) -template< typename Fn1, typename Fn2 > -class wrapper { -private: - typename std::decay< Fn1 >::type fn1_; - typename std::decay< Fn2 >::type fn2_; - boost::context::execution_context ctx_; - -public: - wrapper( Fn1 && fn1, Fn2 && fn2, - boost::context::execution_context const& ctx) : - fn1_( std::move( fn1) ), - fn2_( std::move( fn2) ), - ctx_{ ctx } { - } - - wrapper( wrapper const&) = delete; - wrapper & operator=( wrapper const&) = delete; - - wrapper( wrapper && other) = default; - wrapper & operator=( wrapper && other) = default; - - void operator()( void * vp) { - boost::context::detail::invoke( - std::move( fn1_), - fn2_, ctx_, vp); - } -}; - -template< typename Fn1, typename Fn2 > -wrapper< Fn1, Fn2 > -wrap( Fn1 && fn1, Fn2 && fn2, - boost::context::execution_context const& ctx) { - return wrapper< Fn1, Fn2 >( - std::forward< Fn1 >( fn1), - std::forward< Fn2 >( fn2), - ctx); -} -#else template< typename Fn1, typename Fn2 > class wrapper { private: @@ -101,7 +57,6 @@ wrap( Fn1 && fn1, Fn2 && fn2) { std::forward< Fn1 >( fn1), std::forward< Fn2 >( fn2) ); } -#endif }}} |