diff options
Diffstat (limited to 'boost/coroutine2/detail/pull_control_block_ecv1.ipp')
-rw-r--r-- | boost/coroutine2/detail/pull_control_block_ecv1.ipp | 126 |
1 files changed, 72 insertions, 54 deletions
diff --git a/boost/coroutine2/detail/pull_control_block_ecv1.ipp b/boost/coroutine2/detail/pull_control_block_ecv1.ipp index f271e795df..eb2ae2778f 100644 --- a/boost/coroutine2/detail/pull_control_block_ecv1.ipp +++ b/boost/coroutine2/detail/pull_control_block_ecv1.ipp @@ -36,6 +36,7 @@ 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(); } @@ -52,15 +53,17 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; push_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; - 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(); + 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; @@ -78,15 +81,17 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, typename push_coroutine< T >::control_block synthesized_cb{ this, ctx }; push_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; - 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(); + 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; @@ -120,6 +125,7 @@ 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 @@ -181,6 +187,7 @@ 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(); } @@ -197,15 +204,17 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; push_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; - 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(); + 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; @@ -223,15 +232,17 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo typename push_coroutine< T & >::control_block synthesized_cb{ this, ctx }; push_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; - 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(); + 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; @@ -263,6 +274,7 @@ 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); } } @@ -305,6 +317,7 @@ 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(); } @@ -320,15 +333,17 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; push_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; - 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(); + 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; @@ -346,15 +361,17 @@ pull_coroutine< void >::control_block::control_block( context::preallocated pall typename push_coroutine< void >::control_block synthesized_cb{ this, ctx }; push_coroutine< void > synthesized{ & synthesized_cb }; other = & synthesized_cb; - 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(); + 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; @@ -384,6 +401,7 @@ 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); } } |