From ac27579e48a1f2587cd914355bd865fe225ae04a Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Thu, 26 Mar 2015 09:57:08 +0100 Subject: [PATCH] adapt new API of execution_context --- .../coroutine2/detail/pull_control_block.hpp | 3 - .../coroutine2/detail/pull_control_block.ipp | 60 ++++++------------- .../coroutine2/detail/push_control_block.hpp | 3 - .../coroutine2/detail/push_control_block.ipp | 51 ++++------------ test/test_coroutine.cpp | 14 ++--- 5 files changed, 35 insertions(+), 96 deletions(-) diff --git a/include/boost/coroutine2/detail/pull_control_block.hpp b/include/boost/coroutine2/detail/pull_control_block.hpp index 55c1e19..6ca6fd6 100644 --- a/include/boost/coroutine2/detail/pull_control_block.hpp +++ b/include/boost/coroutine2/detail/pull_control_block.hpp @@ -27,7 +27,6 @@ struct pull_coroutine< T >::control_block { boost::context::execution_context callee; bool preserve_fpu; int state; - std::exception_ptr except; template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&, bool); @@ -51,7 +50,6 @@ struct pull_coroutine< T & >::control_block { boost::context::execution_context callee; bool preserve_fpu; int state; - std::exception_ptr except; template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&, bool); @@ -74,7 +72,6 @@ struct pull_coroutine< void >::control_block { boost::context::execution_context callee; bool preserve_fpu; int state; - std::exception_ptr except; template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&, bool); diff --git a/include/boost/coroutine2/detail/pull_control_block.ipp b/include/boost/coroutine2/detail/pull_control_block.ipp index 5809a1e..1b1b573 100644 --- a/include/boost/coroutine2/detail/pull_control_block.ipp +++ b/include/boost/coroutine2/detail/pull_control_block.ipp @@ -45,20 +45,16 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, 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 |= static_cast< int >( state_t::complete); // jump back to caller - caller.resume( preserve_fpu); + caller( preserve_fpu); BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); }), preserve_fpu( preserve_fpu_), - state( static_cast< int >( state_t::unwind) ), - except() { - callee.resume( preserve_fpu); + state( static_cast< int >( state_t::unwind) ) { + callee( preserve_fpu); } template< typename T > @@ -67,8 +63,7 @@ pull_coroutine< T >::control_block::control_block( typename push_coroutine< T >: caller( other->callee), callee( other->caller), preserve_fpu( other->preserve_fpu), - state( 0), - except() { + state( 0) { } template< typename T > @@ -77,17 +72,14 @@ pull_coroutine< T >::control_block::~control_block() { 0 != ( state & static_cast< int >( state_t::unwind) ) ) { // set early-exit flag state |= static_cast< int >( state_t::early_exit); - callee.resume( preserve_fpu); + callee( preserve_fpu); } } template< typename T > void pull_coroutine< T >::control_block::resume() { - callee.resume( preserve_fpu); - if ( except) { - std::rethrow_exception( except); - } + callee( preserve_fpu); // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); @@ -120,20 +112,16 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo 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 |= static_cast< int >( state_t::complete); // jump back to caller - caller.resume( preserve_fpu); + caller( preserve_fpu); BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); }), preserve_fpu( preserve_fpu_), - state( static_cast< int >( state_t::unwind) ), - except() { - callee.resume( preserve_fpu); + state( static_cast< int >( state_t::unwind) ) { + callee( preserve_fpu); } template< typename T > @@ -142,8 +130,7 @@ pull_coroutine< T & >::control_block::control_block( typename push_coroutine< T caller( other->callee), callee( other->caller), preserve_fpu( other->preserve_fpu), - state( 0), - except() { + state( 0) { } template< typename T > @@ -152,17 +139,14 @@ pull_coroutine< T & >::control_block::~control_block() { 0 != ( state & static_cast< int >( state_t::unwind) ) ) { // set early-exit flag state |= static_cast< int >( state_t::early_exit); - callee.resume( preserve_fpu); + callee( preserve_fpu); } } template< typename T > void pull_coroutine< T & >::control_block::resume() { - callee.resume( preserve_fpu); - if ( except) { - std::rethrow_exception( except); - } + callee( preserve_fpu); // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); @@ -194,20 +178,16 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall 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 |= static_cast< int >( state_t::complete); // jump back to caller - caller.resume( preserve_fpu); + caller( preserve_fpu); BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); }), preserve_fpu( preserve_fpu_), - state( static_cast< int >( state_t::unwind) ), - except() { - callee.resume( preserve_fpu); + state( static_cast< int >( state_t::unwind) ) { + callee( preserve_fpu); } inline @@ -216,8 +196,7 @@ pull_coroutine< void >::control_block::control_block( push_coroutine< void >::co caller( other->callee), callee( other->caller), preserve_fpu( other->preserve_fpu), - state( 0), - except() { + state( 0) { } inline @@ -226,17 +205,14 @@ pull_coroutine< void >::control_block::~control_block() { 0 != ( state & static_cast< int >( state_t::unwind) ) ) { // set early-exit flag state |= static_cast< int >( state_t::early_exit); - callee.resume( preserve_fpu); + callee( preserve_fpu); } } inline void pull_coroutine< void >::control_block::resume() { - callee.resume( preserve_fpu); - if ( except) { - std::rethrow_exception( except); - } + callee( preserve_fpu); // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); diff --git a/include/boost/coroutine2/detail/push_control_block.hpp b/include/boost/coroutine2/detail/push_control_block.hpp index 1b20b7f..a0d8601 100644 --- a/include/boost/coroutine2/detail/push_control_block.hpp +++ b/include/boost/coroutine2/detail/push_control_block.hpp @@ -27,7 +27,6 @@ struct push_coroutine< T >::control_block { boost::context::execution_context callee; bool preserve_fpu; int state; - std::exception_ptr except; T * t; template< typename StackAllocator, typename Fn > @@ -54,7 +53,6 @@ struct push_coroutine< T & >::control_block { boost::context::execution_context callee; bool preserve_fpu; int state; - std::exception_ptr except; T * t; template< typename StackAllocator, typename Fn > @@ -78,7 +76,6 @@ struct push_coroutine< void >::control_block { boost::context::execution_context callee; bool preserve_fpu; int state; - std::exception_ptr except; template< typename StackAllocator, typename Fn > control_block( context::preallocated, StackAllocator, Fn &&, bool); diff --git a/include/boost/coroutine2/detail/push_control_block.ipp b/include/boost/coroutine2/detail/push_control_block.ipp index 6c988ee..3786854 100644 --- a/include/boost/coroutine2/detail/push_control_block.ipp +++ b/include/boost/coroutine2/detail/push_control_block.ipp @@ -46,19 +46,15 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, 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 |= static_cast< int >( state_t::complete); // jump back to caller - caller.resume( preserve_fpu_); + caller( preserve_fpu_); BOOST_ASSERT_MSG( false, "push_coroutine is complete"); }), preserve_fpu( preserve_fpu_), state( static_cast< int >( state_t::unwind) ), - except(), t( nullptr) { } @@ -69,7 +65,6 @@ push_coroutine< T >::control_block::control_block( typename pull_coroutine< T >: callee( other->caller), preserve_fpu( other->preserve_fpu), state( 0), - except(), t( nullptr) { } @@ -79,7 +74,7 @@ push_coroutine< T >::control_block::~control_block() { 0 != ( state & static_cast< int >( state_t::unwind) ) ) { // set early-exit flag state |= static_cast< int >( state_t::early_exit); - callee.resume( preserve_fpu); + callee( preserve_fpu); } } @@ -90,11 +85,8 @@ push_coroutine< T >::control_block::resume( T const& t_) { // pass an pointer (address of tmp) to other context T tmp( t_); t = & tmp; - callee.resume( preserve_fpu); + callee( preserve_fpu); t = nullptr; - if ( except) { - std::rethrow_exception( except); - } // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); @@ -108,11 +100,8 @@ push_coroutine< T >::control_block::resume( T && t_) { // pass an pointer (address of tmp) to other context T tmp( std::move( t_) ); t = & tmp; - callee.resume( preserve_fpu); + callee( preserve_fpu); t = nullptr; - if ( except) { - std::rethrow_exception( except); - } // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); @@ -145,19 +134,15 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo 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 |= static_cast< int >( state_t::complete); // jump back to caller - caller.resume( preserve_fpu_); + caller( preserve_fpu_); BOOST_ASSERT_MSG( false, "push_coroutine is complete"); }), preserve_fpu( preserve_fpu_), state( static_cast< int >( state_t::unwind) ), - except(), t( nullptr) { } @@ -168,7 +153,6 @@ push_coroutine< T & >::control_block::control_block( typename pull_coroutine< T callee( other->caller), preserve_fpu( other->preserve_fpu), state( 0), - except(), t( nullptr) { } @@ -178,7 +162,7 @@ push_coroutine< T & >::control_block::~control_block() { 0 != ( state & static_cast< int >( state_t::unwind) ) ) { // set early-exit flag state |= static_cast< int >( state_t::early_exit); - callee.resume( preserve_fpu); + callee( preserve_fpu); } } @@ -186,11 +170,8 @@ template< typename T > void push_coroutine< T & >::control_block::resume( T & t_) { t = & t_; - callee.resume( preserve_fpu); + callee( preserve_fpu); t = nullptr; - if ( except) { - std::rethrow_exception( except); - } // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); @@ -221,19 +202,15 @@ push_coroutine< void >::control_block::control_block( context::preallocated pall 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 |= static_cast< int >( state_t::complete); // jump back to caller - caller.resume( preserve_fpu_); + caller( preserve_fpu_); BOOST_ASSERT_MSG( false, "push_coroutine is complete"); }), preserve_fpu( preserve_fpu_), - state( static_cast< int >( state_t::unwind) ), - except() { + state( static_cast< int >( state_t::unwind) ) { } inline @@ -242,8 +219,7 @@ push_coroutine< void >::control_block::control_block( pull_coroutine< void >::co caller( other->callee), callee( other->caller), preserve_fpu( other->preserve_fpu), - state( 0), - except() { + state( 0) { } inline @@ -252,17 +228,14 @@ push_coroutine< void >::control_block::~control_block() { 0 != ( state & static_cast< int >( state_t::unwind) ) ) { // set early-exit flag state |= static_cast< int >( state_t::early_exit); - callee.resume( preserve_fpu); + callee( preserve_fpu); } } inline void push_coroutine< void >::control_block::resume() { - callee.resume( preserve_fpu); - if ( except) { - std::rethrow_exception( except); - } + callee( preserve_fpu); // test early-exit-flag if ( 0 != ( ( other->state) & static_cast< int >( state_t::early_exit) ) ) { throw forced_unwind(); diff --git a/test/test_coroutine.cpp b/test/test_coroutine.cpp index 91b5068..7a13a81 100644 --- a/test/test_coroutine.cpp +++ b/test/test_coroutine.cpp @@ -461,8 +461,8 @@ void test_unwind() void test_exceptions() { - bool thrown = false; - std::runtime_error ex("abc"); + std::string msg("abc"), value; + std::runtime_error ex( msg); try { coro::coroutine< void >::push_type coro( @@ -472,13 +472,9 @@ void test_exceptions() BOOST_CHECK( ! coro); BOOST_CHECK( false); } - catch ( std::runtime_error const&) - { thrown = true; } - catch ( std::exception const&) - {} - catch (...) - {} - BOOST_CHECK( thrown); + catch ( std::runtime_error const& ex) + { value = ex.what(); } + BOOST_CHECK_EQUAL( value, msg); } void test_input_iterator()