From a344247f075651bdb2093d7c35a9d73dfea0ffa5 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 25 Nov 2015 19:30:25 +0100 Subject: [PATCH] remove forced_unwind and related functions - unwinding the stack via exception is not always necessary - usually a fiber returns from its fiber-fn (stack is already unwound) - if a fiber has to terminate, interrupt that fiber --- include/boost/fiber/context.hpp | 17 ++--------------- include/boost/fiber/exceptions.hpp | 2 -- src/context.cpp | 7 ------- src/scheduler.cpp | 7 ++----- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp index 4b592a99..b0777c26 100644 --- a/include/boost/fiber/context.hpp +++ b/include/boost/fiber/context.hpp @@ -134,8 +134,7 @@ private: flag_worker_context = 1 << 3, flag_terminated = 1 << 4, flag_interruption_blocked = 1 << 5, - flag_interruption_requested = 1 << 6, - flag_forced_unwind = 1 << 7 + flag_interruption_requested = 1 << 6 }; struct BOOST_FIBERS_DECL fss_data { @@ -284,14 +283,8 @@ public: std::function< void() > * func( static_cast< std::function< void() > * >( vp) ); ( * func)(); } - // check for unwinding - if ( ! unwinding_requested() ) { - boost::context::detail::do_invoke( fn, tpl); - } + boost::context::detail::do_invoke( fn, tpl); } catch ( fiber_interrupted const&) { - } catch ( forced_unwind const&) { - } catch ( ... ) { - std::terminate(); } // terminate context terminate(); @@ -361,12 +354,6 @@ public: void request_interruption( bool req) noexcept; - bool unwinding_requested() const noexcept { - return 0 != ( flags_ & flag_forced_unwind); - } - - void request_unwinding() noexcept; - void * get_fss_data( void const * vp) const; void set_fss_data( diff --git a/include/boost/fiber/exceptions.hpp b/include/boost/fiber/exceptions.hpp index 5af77655..b02d68ae 100644 --- a/include/boost/fiber/exceptions.hpp +++ b/include/boost/fiber/exceptions.hpp @@ -24,8 +24,6 @@ namespace boost { namespace fibers { -struct forced_unwind {}; - class fiber_exception : public std::system_error { public: fiber_exception() : diff --git a/src/context.cpp b/src/context.cpp index 55f74733..b2bfad72 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -334,13 +334,6 @@ context::request_interruption( bool req) noexcept { } } -void -context::request_unwinding() noexcept { - BOOST_ASSERT( ! is_main_context() ); - BOOST_ASSERT( ! is_dispatcher_context() ); - flags_ |= flag_forced_unwind; -} - void * context::get_fss_data( void const * vp) const { uintptr_t key( reinterpret_cast< uintptr_t >( vp) ); diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 84bb1a04..999846b0 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -34,9 +34,6 @@ scheduler::resume_( context * active_ctx, context * ctx, std::function< void() > // resume active-fiber == ctx ctx->resume( func); BOOST_ASSERT( context::active() == active_ctx); - if ( active_ctx->unwinding_requested() ) { - throw forced_unwind(); - } } context * @@ -185,7 +182,7 @@ scheduler::dispatch() { // loop till all context' have been terminated std::unique_lock< detail::spinlock > lk( worker_splk_); while ( ! worker_queue_.empty() ) { - // force unwinding of all context' in worker-queue + // interrupt all context' in worker-queue worker_queue_t::iterator e = worker_queue_.end(); for ( worker_queue_t::iterator i = worker_queue_.begin(); i != e;) { context * ctx = & ( worker_queue_.front() ); @@ -194,7 +191,7 @@ scheduler::dispatch() { if ( ctx->is_terminated() ) { i = worker_queue_.erase( i); } else { - ctx->request_unwinding(); + ctx->request_interruption( true); set_ready( ctx); ++i; }