From 57267ec9571b2172f877af2f73a84349dcb316bf Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Tue, 19 Apr 2016 18:16:31 +0200 Subject: [PATCH] remove support for fiber interruption --- build/Jamfile.v2 | 1 - doc/barrier.qbk | 1 - doc/channel.qbk | 14 +- doc/condition_variables.qbk | 13 +- doc/fiber.qbk | 257 +-------------------- doc/fibers.qbk | 8 - doc/future.qbk | 10 +- doc/mutexes.qbk | 4 +- examples/asio/autoecho.cpp | 7 - examples/asio/detail/yield.hpp | 1 - examples/asio/echo.cpp | 8 - include/boost/fiber/condition_variable.hpp | 9 - include/boost/fiber/context.hpp | 54 ++--- include/boost/fiber/exceptions.hpp | 9 - include/boost/fiber/fiber.hpp | 2 - include/boost/fiber/interruption.hpp | 68 ------ include/boost/fiber/operations.hpp | 5 - src/context.cpp | 24 -- src/fiber.cpp | 8 - src/interruption.cpp | 70 ------ src/scheduler.cpp | 2 - test/test_condition_variable.cpp | 20 -- test/test_condition_variable_any.cpp | 20 -- test/test_fiber.cpp | 108 --------- test/test_fss.cpp | 3 - 25 files changed, 39 insertions(+), 687 deletions(-) delete mode 100644 include/boost/fiber/interruption.hpp delete mode 100644 src/interruption.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index e7444e07..54a1ee59 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -34,7 +34,6 @@ lib boost_fiber detail/spinlock.cpp fiber.cpp future.cpp - interruption.cpp mutex.cpp properties.cpp recursive_mutex.cpp diff --git a/doc/barrier.qbk b/doc/barrier.qbk index 792a486d..510808d9 100644 --- a/doc/barrier.qbk +++ b/doc/barrier.qbk @@ -85,7 +85,6 @@ the barrier is reset. ]] [[Returns:] [`true` for exactly one fiber from each batch of waiting fibers, `false` otherwise.]] [[Throws:] [__fiber_error__]] -[[Notes:] [`wait()` is one of the predefined __interruption_points__.]] ] [endsect] diff --git a/doc/channel.qbk b/doc/channel.qbk index 368f7310..70f32169 100644 --- a/doc/channel.qbk +++ b/doc/channel.qbk @@ -157,7 +157,7 @@ blocked on `this->pop()`, `this->value_pop()`, `this->pop_wait_for()` or fiber gets suspended until at least one new item is `push()`ed (return value `success` and `va` contains dequeued value) or the channel gets `close()`d (return value `closed`)[unblocking]]] -[[Throws:] [__fiber_interrupted__]] +[[Throws:] [Nothing]] ] ] [xchannel_pop unbounded_channel .] @@ -171,7 +171,7 @@ fiber gets suspended until at least one new item is `push()`ed (return value [[Effects:] [Dequeues a value from the channel. If the channel is empty, the fiber gets suspended until at least one new item is `push()`ed or the channel gets `close()`d (which throws an exception)[unblocking]]] -[[Throws:] [`fiber_error` if `*this` is closed or __fiber_interrupted__]] +[[Throws:] [`fiber_error` if `*this` is closed]] [[Error conditions:] [`std::errc::operation_not_permitted`]] ] ] @@ -210,7 +210,7 @@ value `success` and `va` contains dequeued value), or the channel gets [[Effects:] [Accepts `std::chrono::duration` and internally computes a timeout time as (system time + `timeout_duration`). [xchannel_pop_wait_until_effects the computed timeout time..[unblocking]]]] -[[Throws:] [__fiber_interrupted__ or timeout-related exceptions.]] +[[Throws:] [timeout-related exceptions.]] ] ] [xchannel_pop_wait_for unbounded_channel .] @@ -226,7 +226,7 @@ time as (system time + `timeout_duration`). [variablelist [[Effects:] [Accepts a `std::chrono::time_point< Clock, Duration >`. [xchannel_pop_wait_until_effects the passed `time_point`..[unblocking]]]] -[[Throws:] [__fiber_interrupted__ or timeout-related exceptions.]] +[[Throws:] [timeout-related exceptions.]] ] ] [xchannel_pop_wait_until unbounded_channel .] @@ -340,7 +340,7 @@ the number of values in the channel drops to `lwm` (return value [variablelist [[Effects:] [[bounded_channel_push_effects or].]] -[[Throws:] [__fiber_interrupted__ or exceptions thrown by memory +[[Throws:] [exceptions thrown by memory allocation and copying or moving `va`.]] ] @@ -361,7 +361,7 @@ allocation and copying or moving `va`.]] time_point as (system time + `timeout_duration`). [bounded_channel_push_effects ,], or the system time reaches the computed time_point (return value `timeout`).]] -[[Throws:] [__fiber_interrupted__, exceptions thrown by memory +[[Throws:] [exceptions thrown by memory allocation and copying or moving `va` or timeout-related exceptions.]] ] @@ -381,7 +381,7 @@ allocation and copying or moving `va` or timeout-related exceptions.]] [[Effects:] [Accepts an absolute `timeout_time` in any supported time_point type. [bounded_channel_push_effects ,], or the system time reaches the passed time_point (return value `timeout`).]] -[[Throws:] [__fiber_interrupted__ or exceptions thrown by memory +[[Throws:] [exceptions thrown by memory allocation and copying or moving `va` or timeout-related exceptions.]] ] diff --git a/doc/condition_variables.qbk b/doc/condition_variables.qbk index 81224ba0..a321bb23 100644 --- a/doc/condition_variables.qbk +++ b/doc/condition_variables.qbk @@ -266,10 +266,7 @@ while ( ! pred() ) { } ``]] [[Postcondition:] [`lk` is locked by the current fiber.]] -[[Throws:] [__fiber_error__ if an error -occurs, __fiber_interrupted__ if the wait was interrupted by a call to -__interrupt__ on the __fiber__ object associated with the current fiber of -execution.]] +[[Throws:] [__fiber_error__ if an error occurs.]] [[Note:] [The Precondition is a bit dense. It merely states that all the fibers concurrently calling `wait` on `*this` must wait on `lk` objects governing the ['same] [class_link mutex]. Three distinct objects are involved @@ -318,9 +315,7 @@ return true; `pred()` returns `true` at that time.]] [[Postcondition:] [`lk` is locked by the current fiber.]] [[Throws:] [__fiber_error__ if an error -occurs, __fiber_interrupted__ if the wait was interrupted by a call to -__interrupt__ on the __fiber__ object associated with the current fiber of -execution or timeout-related exceptions.]] +occurs or timeout-related exceptions.]] [[Returns:] [The overload without `pred` returns `cv_status::no_timeout` if awakened by `notify_one()` or `notify_all()`, or `cv_status::timeout` if awakened because the system time is past `abs_time`.]] @@ -368,9 +363,7 @@ The point is that, even if `wait_for()` times out, it can still return `true` if `pred()` returns `true` at that time.]] [[Postcondition:] [`lk` is locked by the current fiber.]] [[Throws:] [__fiber_error__ if an error -occurs, __fiber_interrupted__ if the wait was interrupted by a call to -__interrupt__ on the __fiber__ object associated with the current fiber of -execution or timeout-related exceptions.]] +occurs or timeout-related exceptions.]] [[Returns:] [The overload without `pred` returns `cv_status::no_timeout` if awakened by `notify_one()` or `notify_all()`, or `cv_status::timeout` if awakened because at least `rel_time` has elapsed.]] diff --git a/doc/fiber.qbk b/doc/fiber.qbk index 1ab3c237..c59b0856 100644 --- a/doc/fiber.qbk +++ b/doc/fiber.qbk @@ -41,12 +41,6 @@ template< typename PROPS > PROPS & properties(); - void interruption_point(); - bool interruption_requested() noexcept; - bool interruption_enabled() noexcept; - class disable_interruption; - class restore_interruption; - }} @@ -115,12 +109,7 @@ mutex], or [class_link condition_variable], or any of the other [link synchronization synchronization objects] provided by the library. If a detached fiber is still running when the thread's main fiber terminates, -that fiber will be [link interruption interrupted] and shut down.[footnote -This treatment of detached fibers depends on a detached fiber eventually -either terminating or reaching one of the specified __interruption_points__. -Note that since [ns_function_link this_fiber..yield] is ['not] an interruption -point, a detached fiber whose only interaction with the Fiber library is -`yield()` cannot cleanly be terminated.] +the thread will not shut down. [heading Joining] @@ -156,75 +145,6 @@ outlive the __fiber__ object that launched it, use the __detach__ method. } // okay, program continues -[#interruption] -[heading Interruption] - -A valid fiber can be interrupted by invoking its __interrupt__ member function. -The next time that fiber executes one of the specific __interruption_points__ with -interruption enabled, a __fiber_interrupted__ exception will be thrown. -If this exception is not caught, the fiber will be terminated, its stack unwound, -its stack objects properly destroyed. - -(__fiber_interrupted__, being thrown by the library, is similarly caught by -the library. It does not cause the program to terminate.) - -With __disable_interruption__ a fiber can defer being interrupted. - - // interruption enabled at this point - { - boost::this_fiber::disable_interruption di1; - // interruption disabled - { - boost::this::fiber::disable_interruption di2; - // interruption still disabled - } // di2 destroyed; interruption state restored - // interruption still disabled - } // di destroyed; interruption state restored - // interruption enabled - -At any point, the interruption state for the current thread can be queried by -calling __interruption_enabled__. - -(But consider fiber `f1` running a __packaged_task__. Suppose `f1` is -interrupted. Its associated __future__ will be set with __fiber_interrupted__. -When fiber `f2` calls [member_link future..get] on that `future`, `get()` -will immediately rethrow __fiber_interrupted__ [mdash] regardless of -any __disable_interruption__ instance `f2` might have constructed.) - -The following __interruption_points__ are defined and will throw -__fiber_interrupted__ if __interruption_requested__ and -__interruption_enabled__. - -* __join__ -* __barrier_wait__ -* __cond_wait__ -* __cond_wait_for__ -* __cond_wait_until__ -* __cond_any_wait__ -* __cond_any_wait_for__ -* __cond_any_wait_until__ -* __sleep_for__ -* __sleep_until__ -* __interruption_point__ -* [member_link bounded_channel..push] -* [member_link bounded_channel..push_wait_for] -* [member_link bounded_channel..push_wait_until] -* [member_link bounded_channel..pop] -* [member_link bounded_channel..value_pop] -* [member_link bounded_channel..pop_wait_for] -* [member_link bounded_channel..pop_wait_until] -* [member_link unbounded_channel..push] -* [member_link unbounded_channel..pop] -* [member_link unbounded_channel..value_pop] -* [member_link unbounded_channel..pop_wait_for] -* [member_link unbounded_channel..pop_wait_until] -* [member_link future..wait] -* [member_link future..get] -* [member_link future..get_exception_ptr] -* [member_link shared_future..wait] -* [member_link shared_future..get] -* [member_link shared_future..get_exception_ptr] - [#class_fiber_id] [heading Fiber IDs] @@ -279,8 +199,6 @@ operators on __fiber_id__ yield a total order for every non-equal __fiber_id__. void join(); - void interrupt() noexcept; - template< typename PROPS > PROPS & properties(); }; @@ -382,12 +300,10 @@ may not have completed; otherwise `false`.]] [[Effects:] [Waits for the referenced fiber of execution to complete.]] [[Postconditions:] [The fiber of execution referenced on entry has completed. `*this` no longer refers to any fiber of execution.]] -[[Throws:] [__fiber_interrupted__ if the current fiber is interrupted or -`fiber_error`]] +[[Throws:] [`fiber_error`]] [[Error Conditions:] [ [*resource_deadlock_would_occur]: if `this->get_id() == boost::this_fiber::get_id()`. [*invalid_argument]: if the fiber is not __joinable__.]] -[[Notes:] [`join()` is one of the predefined __interruption_points__.]] ] [member_heading fiber..detach] @@ -416,19 +332,6 @@ default-constructed __fiber_id__.]] [[See also:] [[ns_function_link this_fiber..get_id]]] ] -[member_heading fiber..interrupt] - - void interrupt() noexcept; - -[variablelist -[[Effects:] [If `*this` refers to a fiber of execution, request that the fiber -will be interrupted the next time it enters one of the predefined -__interruption_points__ with interruption enabled, or if it is currently -__blocked__ in a call to one of the predefined __interruption_points__ with -interruption enabled.]] -[[Throws:] [Nothing]] -] - [template_member_heading fiber..properties] template< typename PROPS > @@ -629,9 +532,6 @@ from an explicitly-launched thread's thread-function. That is, in many respects the main fiber on each thread can be treated like an explicitly-launched fiber. -However, unlike an explicitly-launched fiber, if __fiber_interrupted__ is -thrown (or rethrown) on a thread's main fiber without being caught, the Fiber -library cannot catch it: `std::terminate()` will be called. namespace boost { namespace this_fiber { @@ -645,12 +545,6 @@ library cannot catch it: `std::terminate()` will be called. template< typename PROPS > PROPS & properties(); - void interruption_point(); - bool interruption_requested() noexcept; - bool interruption_enabled() noexcept; - class disable_interruption; - class restore_interruption; - }} [ns_function_heading this_fiber..get_id] @@ -675,9 +569,7 @@ executing fiber.]] [variablelist [[Effects:] [Suspends the current fiber until the time point specified by `abs_time` has been reached.]] -[[Throws:] [__fiber_interrupted__ if the current fiber is interrupted -or timeout-related exceptions.]] -[[Note:] [`sleep_until()` is one of the predefined __interruption_points__.]] +[[Throws:] [timeout-related exceptions.]] [[Note:] [The current fiber will not resume before `abs_time`, but there are no guarantees about how soon after `abs_time` it might resume.]] [[Note:] [["timeout-related exceptions] are as defined in the C++ Standard, @@ -697,9 +589,7 @@ exceptions are referred to as ['timeout-related exceptions.]]]] [variablelist [[Effects:] [Suspends the current fiber until the time duration specified by `rel_time` has elapsed.]] -[[Throws:] [__fiber_interrupted__ if the current fiber is interrupted -or timeout-related exceptions.]] -[[Note:] [`sleep_for()` is one of the predefined __interruption_points__.]] +[[Throws:] [timeout-related exceptions.]] [[Note:][The current fiber will not resume before `rel_time` has elapsed, but there are no guarantees about how soon after that it might resume.]] ] @@ -713,7 +603,7 @@ there are no guarantees about how soon after that it might resume.]] [variablelist [[Effects:] [Reliquishes execution control, allowing other fibers to run.]] [[Throws:] [Nothing.]] -[[Note:] [`yield()` is ['not] an interruption point. A fiber that calls +[[Note:] [A fiber that calls `yield()` is not suspended: it is immediately passed to the scheduler as ready to run.]] ] @@ -743,143 +633,6 @@ thread, it may internally yield, permitting other fibers to run.]] [[See also:] [[link custom Customization]]] ] -[ns_function_heading this_fiber..interruption_point] - - #include - - void interruption_point(); - -[variablelist -[[Effects:] [Check to see if the current fiber has been interrupted.]] -[[Throws:] [__fiber_interrupted__ if __interruption_enabled__ and -__interruption_requested__ both return `true`.]] -] - -[ns_function_heading this_fiber..interruption_requested] - - #include - - bool interruption_requested() noexcept; - -[variablelist -[[Returns:] [`true` if interruption has been requested for the current fiber, -`false` otherwise.]] -[[Throws:] [Nothing.]] -] - -[ns_function_heading this_fiber..interruption_enabled] - - #include - - bool interruption_enabled() noexcept; - -[variablelist -[[Returns:] [`true` if interruption is enabled for the current fiber, -`false` otherwise.]] -[[Throws:] [Nothing.]] -[[Note:][Interruption is enabled by default.]] -] - -[class_heading disable_interruption] - - #include - - class disable_interruption { - public: - disable_interruption() noexcept; - ~disable_interruption() noexcept; - disable_interruption(const disable_interruption&) = delete; - disable_interruption& operator=(const disable_interruption&) = delete; - }; - -[heading Constructor] - - disable_interruption() noexcept; - -[variablelist -[[Effects:] [Stores the current state of __interruption_enabled__ and disables -interruption for the current fiber.]] -[[Postconditions:] [__interruption_enabled__ returns `false` for the current -fiber.]] -[[Throws:] [Nothing.]] -[[Note:] [Nesting of `disable_interruption` instances matters. Constructing a -`disable_interruption` while __interruption_enabled__ `== false` has no -effect.]] -] - -[heading Destructor] - - ~disable_interruption() noexcept; - -[variablelist -[[Preconditions:] [Must be called from the same fiber on which `*this` was -constructed.]] -[[Effects:] [Restores the state of __interruption_enabled__ for the -current fiber to the state saved at construction of `*this`.]] -[[Postconditions:] [__interruption_enabled__ for the current fiber returns the -value stored by the constructor of `*this`.]] -[[Note:] [Destroying a `disable_interruption` constructed while -__interruption_enabled__ `== false` has no effect.]] -] - - -[class_heading restore_interruption] - - #include - - class restore_interruption { - public: - explicit restore_interruption(disable_interruption&) noexcept; - ~restore_interruption() noexcept; - restore_interruption(const restore_interruption&) = delete; - restore_interruption& operator=(const restore_interruption&) = delete; - }; - -[heading Constructor] - - explicit restore_interruption(disable_interruption& disabler) noexcept; - -[variablelist -[[Preconditions:] [Must be called from the same fiber on which `disabler` was -constructed.]] -[[Effects:] [Restores the current state of __interruption_enabled__ for the -current fiber to that saved in `disabler`.]] -[[Postconditions:] [__interruption_enabled__ for the current fiber returns the -value stored in the constructor of `disabler`.]] -[[Throws:] [Nothing.]] -[[Note:] [Nesting of `restore_interruption` instances does not matter: only -the [class_link disable_interruption] instance passed to the constructor -matters. Constructing a `restore_interruption` with a `disable_interruption` -constructed while __interruption_enabled__ `== false` has no effect.]] -] - -[heading Destructor] - - ~restore_interruption() noexcept; - -[variablelist -[[Preconditions:] [Must be called from the same fiber on which `*this` was -constructed.]] -[[Effects:] [Disables interruption for the current fiber.]] -[[Postconditions:] [__interruption_enabled__ for the current fiber returns -`false`.]] -[[Note:] [Destroying a `restore_interruption` constructed with a [class_link -disable_interruption] constructed while __interruption_enabled__ `== false` -has no effect.]] -] - - void foo() { - // interruption is enabled - { - boost::this_fiber::disable_interruption di; - // interruption is disabled - { - boost::this_fiber::restore_interruption ri( di); - // interruption now enabled - } // ri destroyed, interruption disabled again - } // di destructed, interruption state restored - // interruption now enabled - } [endsect] [/ section Namespace this_fiber] diff --git a/doc/fibers.qbk b/doc/fibers.qbk index 64d5fb78..033500d6 100644 --- a/doc/fibers.qbk +++ b/doc/fibers.qbk @@ -29,7 +29,6 @@ [def __async_result__ ['async-result]] [def __blocked__ [link blocking ['blocked]]] -[def __interruption_points__ [link interruption ['interruption-points]]] [def __lockable_concept__ ['lockable concept]] [def __not_a_fiber__ ['not-a-fiber]] [def __rendezvous__ ['rendezvous]] @@ -103,18 +102,15 @@ [def __allocator__ [@http://en.cppreference.com/w/cpp/memory/allocator `std::allocator< T >`]] [def __barrier__ [class_link barrier]] [def __condition__ [class_link condition_variable]] -[def __disable_interruption__ [class_link disable_interruption]] [def __econtext__ [@http://www.boost.org/doc/libs/release/libs/context/doc/html/context/econtext.html ['execution_context]]] [def __fiber__ [class_link fiber]] [def __fiber_error__ `fiber_error`] [def __fiber_group__ [class_link fiber_group]] -[def __fiber_interrupted__ `fiber_interrupted`] [def __fiber_error__ `fiber_error`] [def __fibers__ `fibers`] [def __fixedsize_stack__ [class_link fixedsize_stack]] [def __future_error__ `future_error`] [def __future__ [template_link future]] -[def __interruption_point__ [ns_function_link this_fiber..interruption_point]] [def __joinable__ [member_link fiber..joinable]] [def __lock_error__ `lock_error`] [def __mutex__ [class_link mutex]] @@ -124,7 +120,6 @@ [def __promise__ [template_link promise]] [def __recursive_mutex__ [class_link recursive_mutex]] [def __recursive_timed_mutex__ [class_link recursive_timed_mutex]] -[def __restore_interruption__ [class_link restore_interruption]] [def __segmented_stack__ [class_link segmented_stack]] [def __segmented_stack_stack__ ['segmented_stack-stack]] [def __shared_future__ [template_link shared_future]] @@ -160,9 +155,6 @@ [def __fsp__ [class_link fiber_specific_ptr]] [def __future_get__ [member_link future..get]] [def __get_id__ [member_link fiber..get_id]] -[def __interruption_enabled__ [ns_function_link this_fiber..interruption_enabled]] -[def __interruption_requested__ [ns_function_link this_fiber..interruption_requested]] -[def __interrupt__ [member_link fiber..interrupt]] [def __io_service__ `boost::asio::io_service`] [def __join__ [member_link fiber..join]] [def __migrate__ [member_link context..migrate]] diff --git a/doc/future.qbk b/doc/future.qbk index 90b29ee4..01956657 100644 --- a/doc/future.qbk +++ b/doc/future.qbk @@ -191,7 +191,7 @@ called, returns the value. If [member_link promise..set_exception] is called, throws the indicated exception.]] [[Postcondition:] [`false == valid()`]] [[Throws:] [__future_error__ with error condition __no_state__, -__fiber_interrupted__, __broken_promise__. Any exception passed to +__broken_promise__. Any exception passed to `promise::set_exception()`.]] ] ] @@ -207,7 +207,7 @@ __fiber_interrupted__, __broken_promise__. Any exception passed to [[Returns:] [[future_method_wait .] If `set_value()` is called, returns a default-constructed `std::exception_ptr`. If `set_exception()` is called, returns the passed `std::exception_ptr`.]] -[[Throws:] [__future_error__ with error condition __no_state__ or __fiber_interrupted__.]] +[[Throws:] [__future_error__ with error condition __no_state__.]] [[Note:] [ `get_exception_ptr()` does ['not] invalidate the [`[xfuture]]. After calling `get_exception_ptr()`, you may still call [member_link [xfuture]..get].]] @@ -222,7 +222,7 @@ After calling `get_exception_ptr()`, you may still call [member_link [variablelist [[Effects:] [[future_method_wait .]]] -[[Throws:] [__future_error__ with error condition __no_state__ or __fiber_interrupted__.]] +[[Throws:] [__future_error__ with error condition __no_state__.]] ] [template_member_heading [xfuture]..wait_for] @@ -233,7 +233,7 @@ After calling `get_exception_ptr()`, you may still call [member_link [variablelist [[Effects:] [[future_method_wait , or `timeout_duration` has passed.]]] [[Result:] [A `future_status` is returned indicating the reason for returning.]] -[[Throws:] [__future_error__ with error condition __no_state__ or __fiber_interrupted__ or +[[Throws:] [__future_error__ with error condition __no_state__ or timeout-related exceptions.]] ] @@ -245,7 +245,7 @@ timeout-related exceptions.]] [variablelist [[Effects:] [[future_method_wait , or `timeout_time` has passed.]]] [[Result:] [A `future_status` is returned indicating the reason for returning.]] -[[Throws:] [__future_error__ with error condition __no_state__ or __fiber_interrupted__ or +[[Throws:] [__future_error__ with error condition __no_state__ or timeout-related exceptions.]] ] ] diff --git a/doc/mutexes.qbk b/doc/mutexes.qbk index cef759e0..9e4bcb66 100644 --- a/doc/mutexes.qbk +++ b/doc/mutexes.qbk @@ -205,7 +205,7 @@ acquired by another fiber. [variablelist [[Effects:] [The current fiber blocks until ownership can be obtained.]] -[[Throws:] [__fiber_interrupted__]] +[[Throws:] [Nothing]] ] [member_heading recursive_mutex..try_lock] @@ -271,7 +271,7 @@ fiber. [variablelist [[Effects:] [The current fiber blocks until ownership can be obtained.]] -[[Throws:] [__fiber_interrupted__]] +[[Throws:] [Nothing]] ] [member_heading recursive_timed_mutex..try_lock] diff --git a/examples/asio/autoecho.cpp b/examples/asio/autoecho.cpp index e5f369ea..18bdbf35 100644 --- a/examples/asio/autoecho.cpp +++ b/examples/asio/autoecho.cpp @@ -144,8 +144,6 @@ void session( socket_ptr sock) { } } print( tag(), " : connection closed"); - } catch ( boost::fibers::fiber_interrupted const&) { - print( tag(), " : interrupted"); } catch ( std::exception const& ex) { print( tag(), " : caught exception : ", ex.what()); } @@ -170,8 +168,6 @@ void server( boost::asio::io_service & io_svc) { boost::fibers::fiber( session, socket).detach(); } } - } catch ( boost::fibers::fiber_interrupted const&) { - print( tag(), " : interrupted"); } catch ( std::exception const& ex) { print( tag(), " : catched exception : ", ex.what()); } @@ -253,15 +249,12 @@ int main( int argc, char* argv[]) { } boost::fibers::asio::run_svc( io_svc); print( "Thread ", thread_names.lookup(), ": stopping"); - } catch ( boost::fibers::fiber_interrupted const&) { - print( tag(), " : interrupted"); } catch ( std::exception const& ex) { print( tag(), " : catched exception : ", ex.what()); } }); boost::fibers::asio::run_svc( io_svc); print( tag(), " : back from io_service::run(), waiting for server fiber"); - f.interrupt(); f.join(); print( tag(), " : back from thread.join(), waiting for thread"); t.join(); diff --git a/examples/asio/detail/yield.hpp b/examples/asio/detail/yield.hpp index 973673cb..47da304b 100644 --- a/examples/asio/detail/yield.hpp +++ b/examples/asio/detail/yield.hpp @@ -198,7 +198,6 @@ public: if ( ec_) { throw_exception( boost::system::system_error{ ec_ } ); } - boost::this_fiber::interruption_point(); } private: diff --git a/examples/asio/echo.cpp b/examples/asio/echo.cpp index f11ee9f8..9ef8dc3d 100644 --- a/examples/asio/echo.cpp +++ b/examples/asio/echo.cpp @@ -48,10 +48,6 @@ void session( socket_ptr sock) { throw boost::system::system_error( ec); //some other error } } - } catch ( boost::fibers::fiber_interrupted const&) { - std::ostringstream buffer; - buffer << "tid=" << std::this_thread::get_id() << ", fid=" << id << " : interrupted" << std::endl; - std::cerr << buffer.str() << std::flush; } catch ( std::exception const& ex) { std::ostringstream buffer; buffer << "tid=" << std::this_thread::get_id() << ", fid=" << id << " : catched exception : " << ex.what() << std::endl; @@ -78,10 +74,6 @@ void server( boost::asio::io_service & io_svc) { boost::fibers::fiber( session, socket).detach(); } } - } catch ( boost::fibers::fiber_interrupted const&) { - std::ostringstream buffer; - buffer << "tid=" << std::this_thread::get_id() << ", fid=" << id << " : interrupted" << std::endl; - std::cerr << buffer.str() << std::flush; } catch ( std::exception const& ex) { std::ostringstream buffer; buffer << "tid=" << std::this_thread::get_id() << ", fid=" << id << " : catched exception : " << ex.what() << std::endl; diff --git a/include/boost/fiber/condition_variable.hpp b/include/boost/fiber/condition_variable.hpp index 628680e3..590584a9 100644 --- a/include/boost/fiber/condition_variable.hpp +++ b/include/boost/fiber/condition_variable.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -60,8 +59,6 @@ public: template< typename LockType > void wait( LockType & lt) { - // check if context was interrupted - this_fiber::interruption_point(); context * ctx = context::active(); // atomically call lt.unlock() and block on *this // store this fiber in waiting-queue @@ -86,8 +83,6 @@ public: } // post-conditions BOOST_ASSERT( ! ctx->wait_is_linked() ); - // check if context was interrupted - this_fiber::interruption_point(); } template< typename LockType, typename Pred > @@ -99,8 +94,6 @@ public: template< typename LockType, typename Clock, typename Duration > cv_status wait_until( LockType & lt, std::chrono::time_point< Clock, Duration > const& timeout_time_) { - // check if context was interrupted - this_fiber::interruption_point(); cv_status status = cv_status::no_timeout; std::chrono::steady_clock::time_point timeout_time( detail::convert( timeout_time_) ); @@ -130,8 +123,6 @@ public: } // post-conditions BOOST_ASSERT( ! ctx->wait_is_linked() ); - // check if context was interrupted - this_fiber::interruption_point(); return status; } diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp index 6e7bdc8e..09474369 100644 --- a/include/boost/fiber/context.hpp +++ b/include/boost/fiber/context.hpp @@ -125,9 +125,7 @@ private: friend class scheduler; enum flag_t { - flag_terminated = 1 << 1, - flag_interruption_blocked = 1 << 2, - flag_interruption_requested = 1 << 3 + flag_terminated = 1 << 1 }; struct BOOST_FIBERS_DECL fss_data { @@ -175,17 +173,14 @@ private: #if (BOOST_EXECUTION_CONTEXT==1) template< typename Fn, typename Tpl > void run_( Fn && fn_, Tpl && tpl_, detail::data_t * dp) noexcept { - try { - typename std::decay< Fn >::type fn = std::forward< Fn >( fn_); - typename std::decay< Tpl >::type tpl = std::forward< Tpl >( tpl_); - if ( nullptr != dp->lk) { - dp->lk->unlock(); - } else if ( nullptr != dp->ctx) { - active_->set_ready_( dp->ctx); - } - boost::context::detail::apply( std::move( fn), std::move( tpl) ); - } catch ( fiber_interrupted const&) { + typename std::decay< Fn >::type fn = std::forward< Fn >( fn_); + typename std::decay< Tpl >::type tpl = std::forward< Tpl >( tpl_); + if ( nullptr != dp->lk) { + dp->lk->unlock(); + } else if ( nullptr != dp->ctx) { + active_->set_ready_( dp->ctx); } + boost::context::detail::apply( std::move( fn), std::move( tpl) ); // terminate context set_terminated(); BOOST_ASSERT_MSG( false, "fiber already terminated"); @@ -194,19 +189,16 @@ private: template< typename Fn, typename Tpl > boost::context::execution_context< detail::data_t * > run_( boost::context::execution_context< detail::data_t * > ctx, Fn && fn_, Tpl && tpl_, detail::data_t * dp) noexcept { - try { - typename std::decay< Fn >::type fn = std::forward< Fn >( fn_); - typename std::decay< Tpl >::type tpl = std::forward< Tpl >( tpl_); - // update execution_context of calling fiber - dp->from->ctx_ = std::move( ctx); - if ( nullptr != dp->lk) { - dp->lk->unlock(); - } else if ( nullptr != dp->ctx) { - active_->set_ready_( dp->ctx); - } - boost::context::detail::apply( std::move( fn), std::move( tpl) ); - } catch ( fiber_interrupted const&) { + typename std::decay< Fn >::type fn = std::forward< Fn >( fn_); + typename std::decay< Tpl >::type tpl = std::forward< Tpl >( tpl_); + // update execution_context of calling fiber + dp->from->ctx_ = std::move( ctx); + if ( nullptr != dp->lk) { + dp->lk->unlock(); + } else if ( nullptr != dp->ctx) { + active_->set_ready_( dp->ctx); } + boost::context::detail::apply( std::move( fn), std::move( tpl) ); // terminate context return set_terminated(); } @@ -389,18 +381,6 @@ public: return 0 != ( flags_ & flag_terminated); } - bool interruption_blocked() const noexcept { - return 0 != ( flags_ & flag_interruption_blocked); - } - - void interruption_blocked( bool blck) noexcept; - - bool interruption_requested() const noexcept { - return 0 != ( flags_ & flag_interruption_requested); - } - - void request_interruption( bool req) 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 267d076e..ddbf45ea 100644 --- a/include/boost/fiber/exceptions.hpp +++ b/include/boost/fiber/exceptions.hpp @@ -57,15 +57,6 @@ public: } }; -class fiber_interrupted : public fiber_error { -public: - fiber_interrupted() : - fiber_error( - std::make_error_code( std::errc::interrupted) ) { - } -}; - - enum class future_errc { broken_promise = 1, future_already_retrieved, diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index 3be069ea..e23b2f6e 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -100,8 +100,6 @@ public: void join(); - void interrupt() noexcept; - void detach(); template< typename PROPS > diff --git a/include/boost/fiber/interruption.hpp b/include/boost/fiber/interruption.hpp deleted file mode 100644 index fb7cefb9..00000000 --- a/include/boost/fiber/interruption.hpp +++ /dev/null @@ -1,68 +0,0 @@ - -// Copyright Oliver Kowalke 2013. -// 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) -// -// based on boost.thread - -#ifndef BOOST_THIS_FIBER_INTERRUPTION_H -#define BOOST_THIS_FIBER_INTERRUPTION_H - -#include - -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace this_fiber { - -class restore_interruption; - -class BOOST_FIBERS_DECL disable_interruption { -private: - friend class restore_interruption; - - bool set_; - -public: - disable_interruption() noexcept; - - ~disable_interruption(); - - disable_interruption( disable_interruption const&) = delete; - disable_interruption & operator=( disable_interruption const&) = delete; -}; - -class BOOST_FIBERS_DECL restore_interruption { -private: - disable_interruption & disabler_; - -public: - explicit restore_interruption( disable_interruption & disabler) noexcept; - - ~restore_interruption(); - - restore_interruption( restore_interruption const&) = delete; - restore_interruption & operator=( restore_interruption const&) = delete; -}; - -BOOST_FIBERS_DECL -bool interruption_enabled() noexcept; - -BOOST_FIBERS_DECL -bool interruption_requested() noexcept; - -BOOST_FIBERS_DECL -void interruption_point(); - -}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_THIS_FIBER_INTERRUPTION_H diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 99323e1e..2821caaa 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -39,16 +38,12 @@ void sleep_until( std::chrono::time_point< Clock, Duration > const& sleep_time_) std::chrono::steady_clock::time_point sleep_time( boost::fibers::detail::convert( sleep_time_) ); fibers::context::active()->wait_until( sleep_time); - // check if fiber was interrupted - interruption_point(); } template< typename Rep, typename Period > void sleep_for( std::chrono::duration< Rep, Period > const& timeout_duration) { fibers::context::active()->wait_until( std::chrono::steady_clock::now() + timeout_duration); - // check if fiber was interrupted - interruption_point(); } template< typename PROPS > diff --git a/src/context.cpp b/src/context.cpp index 7d2c5daa..dac4dafd 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -11,7 +11,6 @@ #include #include "boost/fiber/exceptions.hpp" -#include "boost/fiber/interruption.hpp" #include "boost/fiber/scheduler.hpp" #ifdef BOOST_HAS_ABI_HEADERS @@ -301,8 +300,6 @@ void context::join() { // get active context context * active_ctx = context::active(); - // context::join() is a interruption point - this_fiber::interruption_point(); // protect for concurrent access std::unique_lock< detail::spinlock > lk( splk_); // wait for context which is not terminated @@ -319,8 +316,6 @@ context::join() { // active context resumed BOOST_ASSERT( context::active() == active_ctx); } - // context::join() is a interruption point - this_fiber::interruption_point(); } void @@ -407,25 +402,6 @@ context::set_ready( context * ctx) noexcept { } } -void -context::interruption_blocked( bool blck) noexcept { - if ( blck) { - flags_ |= flag_interruption_blocked; - } else { - flags_ &= ~flag_interruption_blocked; - } -} - -void -context::request_interruption( bool req) noexcept { - BOOST_ASSERT( ! is_context( type::main_context) && ! is_context( type::dispatcher_context) ); - if ( req) { - flags_ |= flag_interruption_requested; - } else { - flags_ &= ~flag_interruption_requested; - } -} - void * context::get_fss_data( void const * vp) const { uintptr_t key( reinterpret_cast< uintptr_t >( vp) ); diff --git a/src/fiber.cpp b/src/fiber.cpp index 8e9d813e..ece444ab 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -11,7 +11,6 @@ #include #include "boost/fiber/exceptions.hpp" -#include "boost/fiber/interruption.hpp" #include "boost/fiber/scheduler.hpp" #ifdef BOOST_HAS_ABI_HEADERS @@ -44,13 +43,6 @@ fiber::join() { impl_.reset(); } -void -fiber::interrupt() noexcept { - BOOST_ASSERT( nullptr != impl_.get() ); - impl_->request_interruption( true); - context::active()->set_ready( impl_.get() ); -} - void fiber::detach() { if ( ! joinable() ) { diff --git a/src/interruption.cpp b/src/interruption.cpp deleted file mode 100644 index 65f1e472..00000000 --- a/src/interruption.cpp +++ /dev/null @@ -1,70 +0,0 @@ - -// Copyright Oliver Kowalke 2013. -// 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) -// -// based on boost.thread - -#include "boost/fiber/interruption.hpp" - -#include "boost/fiber/context.hpp" -#include "boost/fiber/scheduler.hpp" -#include "boost/fiber/exceptions.hpp" - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace this_fiber { - -disable_interruption::disable_interruption() noexcept : - set_{ fibers::context::active()->interruption_blocked() } { - if ( ! set_) { - fibers::context::active()->interruption_blocked( true); - } -} - -disable_interruption::~disable_interruption() { - if ( ! set_) { - fibers::context::active()->interruption_blocked( false); - } -} - -restore_interruption::restore_interruption( disable_interruption & disabler) noexcept : - disabler_{ disabler } { - if ( ! disabler_.set_) { - fibers::context::active()->interruption_blocked( false); - } -} - -restore_interruption::~restore_interruption() { - if ( ! disabler_.set_) { - fibers::context::active()->interruption_blocked( true); - } -} - -BOOST_FIBERS_DECL -bool interruption_enabled() noexcept { - return ! fibers::context::active()->interruption_blocked(); -} - -BOOST_FIBERS_DECL -bool interruption_requested() noexcept { - return fibers::context::active()->interruption_requested(); -} - -BOOST_FIBERS_DECL -void interruption_point() { - if ( interruption_requested() && interruption_enabled() ) { - fibers::context::active()->request_interruption( false); - throw fibers::fiber_interrupted(); - } -} - -}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif diff --git a/src/scheduler.cpp b/src/scheduler.cpp index f7967ca7..f81e2de5 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -202,8 +202,6 @@ scheduler::set_ready( context * ctx) noexcept { ctx->sleep_unlink(); } // for safety unlink it from ready-queue - // this might happen if a newly created fiber was - // signaled to interrupt ctx->ready_unlink(); // push new context to ready-queue sched_algo_->awakened( ctx); diff --git a/test/test_condition_variable.cpp b/test/test_condition_variable.cpp index ee72f5a9..03abbeb5 100644 --- a/test/test_condition_variable.cpp +++ b/test/test_condition_variable.cpp @@ -80,25 +80,6 @@ void wait_fn( ++value; } -void test_condition_wait_is_a_interruption_point() { - { - condition_test_data data; - boost::fibers::fiber f( & condition_test_fiber, &data); - - f.interrupt(); - f.join(); - BOOST_CHECK_EQUAL(data.awoken,0); - } - { - condition_test_data data; - boost::fibers::fiber f( & condition_test_fiber, &data); - boost::this_fiber::yield(); - f.interrupt(); - f.join(); - BOOST_CHECK_EQUAL(data.awoken,0); - } -} - void test_one_waiter_notify_one() { value = 0; boost::fibers::mutex mtx; @@ -494,7 +475,6 @@ boost::unit_test::test_suite * init_unit_test_suite( int, char* []) test->add( BOOST_TEST_CASE( & test_two_waiter_notify_one) ); test->add( BOOST_TEST_CASE( & test_two_waiter_notify_all) ); test->add( BOOST_TEST_CASE( & test_condition_wait) ); - test->add( BOOST_TEST_CASE( & test_condition_wait_is_a_interruption_point) ); test->add( BOOST_TEST_CASE( & test_condition_wait_until) ); test->add( BOOST_TEST_CASE( & test_condition_wait_until_pred) ); test->add( BOOST_TEST_CASE( & test_condition_wait_for) ); diff --git a/test/test_condition_variable_any.cpp b/test/test_condition_variable_any.cpp index 5f3d77b4..83353f39 100644 --- a/test/test_condition_variable_any.cpp +++ b/test/test_condition_variable_any.cpp @@ -82,25 +82,6 @@ void wait_fn( mtx.unlock(); } -void test_condition_wait_is_a_interruption_point() { - { - condition_test_data data; - boost::fibers::fiber f( & condition_test_fiber, &data); - - f.interrupt(); - f.join(); - BOOST_CHECK_EQUAL(data.awoken,0); - } - { - condition_test_data data; - boost::fibers::fiber f( & condition_test_fiber, &data); - boost::this_fiber::yield(); - f.interrupt(); - f.join(); - BOOST_CHECK_EQUAL(data.awoken,0); - } -} - void test_one_waiter_notify_one() { value = 0; boost::fibers::mutex mtx; @@ -500,7 +481,6 @@ boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { test->add( BOOST_TEST_CASE( & test_two_waiter_notify_one) ); test->add( BOOST_TEST_CASE( & test_two_waiter_notify_all) ); test->add( BOOST_TEST_CASE( & test_condition_wait) ); - test->add( BOOST_TEST_CASE( & test_condition_wait_is_a_interruption_point) ); test->add( BOOST_TEST_CASE( & test_condition_wait_until) ); test->add( BOOST_TEST_CASE( & test_condition_wait_until_pred) ); test->add( BOOST_TEST_CASE( & test_condition_wait_for) ); diff --git a/test/test_fiber.cpp b/test/test_fiber.cpp index 29a3f65b..6e127aab 100644 --- a/test/test_fiber.cpp +++ b/test/test_fiber.cpp @@ -403,113 +403,10 @@ void test_sleep_until() { } } -void interruption_point_fiber(boost::fibers::mutex* m,bool* failed) { - std::unique_lock lk(*m); - boost::this_fiber::interruption_point(); - *failed=true; -} - -void test_fiber_interrupts_at_interruption_point() { - boost::fibers::mutex m; - bool failed=false; - std::unique_lock lk(m); - boost::fibers::fiber f(interruption_point_fiber,&m,&failed); - f.interrupt(); - lk.unlock(); - f.join(); - BOOST_CHECK(!failed); -} - -void disabled_interruption_point_fiber(boost::fibers::mutex* m,bool* failed) { - std::unique_lock lk(*m); - boost::this_fiber::disable_interruption dc; - boost::this_fiber::interruption_point(); - *failed=false; -} - -void test_fiber_no_interrupt_if_interrupts_disabled_at_interruption_point() { - boost::fibers::mutex m; - bool failed=true; - std::unique_lock lk(m); - boost::fibers::fiber f(disabled_interruption_point_fiber,&m,&failed); - f.interrupt(); - lk.unlock(); - f.join(); - BOOST_CHECK(!failed); -} - void do_wait( boost::fibers::barrier* b) { b->wait(); } -void do_join( boost::fibers::fiber * f, bool * interrupted) { - try { - f->join(); - } catch ( ... ) { - * interrupted = true; - } -} - -void test_fiber_interrupt_at_join() { - { - bool interrupted=false; - boost::fibers::barrier b( 2); - boost::fibers::fiber f1(do_wait, & b); - boost::fibers::fiber f2(do_join, & f1, & interrupted); - f2.interrupt(); - f2.join(); - b.wait(); - f1.join(); - BOOST_CHECK(interrupted); - } - { - bool interrupted=false; - boost::fibers::barrier b( 2); - boost::fibers::fiber f1(do_wait, & b); - boost::fibers::fiber f2(do_join, & f1, & interrupted); - boost::this_fiber::yield(); - f2.interrupt(); - f2.join(); - b.wait(); - f1.join(); - BOOST_CHECK(interrupted); - } -} - -void do_sleep_for( std::chrono::seconds const& s, bool * interrupted) { - try { - boost::this_fiber::sleep_for( s); - } catch ( boost::fibers::fiber_interrupted const&) { - * interrupted = true; - } -} - -void test_sleep_for_is_interruption_point() { - bool interrupted=false; - boost::fibers::fiber f(do_sleep_for, std::chrono::seconds(1), & interrupted); - boost::this_fiber::yield(); - f.interrupt(); - f.join(); - BOOST_CHECK(interrupted); -} - -void do_sleep_until( std::chrono::seconds const& s, bool * interrupted) { - try { - boost::this_fiber::sleep_until( std::chrono::steady_clock::now() + s); - } catch ( boost::fibers::fiber_interrupted const&) { - * interrupted = true; - } -} - -void test_sleep_until_is_interruption_point() { - bool interrupted=false; - boost::fibers::fiber f(do_sleep_until, std::chrono::seconds(1), & interrupted); - boost::this_fiber::yield(); - f.interrupt(); - f.join(); - BOOST_CHECK(interrupted); -} - void test_detach() { { boost::fibers::fiber f( (detachable()) ); @@ -549,11 +446,6 @@ boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { test->add( BOOST_TEST_CASE( & test_yield) ); test->add( BOOST_TEST_CASE( & test_sleep_for) ); test->add( BOOST_TEST_CASE( & test_sleep_until) ); - test->add( BOOST_TEST_CASE( & test_fiber_interrupts_at_interruption_point) ); - test->add( BOOST_TEST_CASE( & test_fiber_no_interrupt_if_interrupts_disabled_at_interruption_point) ); - test->add( BOOST_TEST_CASE( & test_fiber_interrupt_at_join) ); - test->add( BOOST_TEST_CASE( & test_sleep_for_is_interruption_point) ); - test->add( BOOST_TEST_CASE( & test_sleep_until_is_interruption_point) ); test->add( BOOST_TEST_CASE( & test_detach) ); return test; diff --git a/test/test_fss.cpp b/test/test_fss.cpp index 14a61cca..44ced674 100644 --- a/test/test_fss.cpp +++ b/test/test_fss.cpp @@ -95,7 +95,6 @@ void fss_with_custom_cleanup() { try { f.join(); } catch(...) { - f.interrupt(); f.join(); throw; } @@ -120,7 +119,6 @@ void do_test_fss_does_no_cleanup_after_release() { try { f.join(); } catch(...) { - f.interrupt(); f.join(); throw; } @@ -154,7 +152,6 @@ void do_test_fss_does_no_cleanup_with_null_cleanup_function() { try { f.join(); } catch(...) { - f.interrupt(); f.join(); throw; }