diff --git a/include/boost/fiber/algorithm.hpp b/include/boost/fiber/algorithm.hpp index 2c1ae4cc..d19eb48d 100644 --- a/include/boost/fiber/algorithm.hpp +++ b/include/boost/fiber/algorithm.hpp @@ -1,4 +1,4 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/asio/detail/spawn.hpp b/include/boost/fiber/asio/detail/spawn.hpp index 4c11c690..feb83c1a 100644 --- a/include/boost/fiber/asio/detail/spawn.hpp +++ b/include/boost/fiber/asio/detail/spawn.hpp @@ -50,7 +50,7 @@ public: * ec_ = boost::system::error_code(); * value_ = value; fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } void operator()( boost::system::error_code ec, T value) @@ -58,7 +58,7 @@ public: * ec_ = ec; * value_ = value; fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } //private: @@ -83,14 +83,14 @@ public: { * ec_ = boost::system::error_code(); fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } void operator()( boost::system::error_code ec) { * ec_ = ec; fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } //private: @@ -187,8 +187,8 @@ public: type get() { - boost::fibers::detail::scheduler::instance().active()->set_waiting(); - boost::fibers::detail::scheduler::instance().active()->suspend(); + boost::fibers::detail::scheduler::instance()->active()->set_waiting(); + boost::fibers::detail::scheduler::instance()->active()->suspend(); if ( ! out_ec_ && ec_) throw boost::system::system_error( ec_); return value_; } @@ -214,8 +214,8 @@ public: void get() { - boost::fibers::detail::scheduler::instance().active()->set_waiting(); - boost::fibers::detail::scheduler::instance().active()->suspend(); + boost::fibers::detail::scheduler::instance()->active()->set_waiting(); + boost::fibers::detail::scheduler::instance()->active()->suspend(); if ( ! out_ec_ && ec_) throw boost::system::system_error( ec_); } @@ -252,8 +252,8 @@ struct fiber_entry_point void operator()() { shared_ptr< spawn_data< Handler, Function > > data( data_); - boost::fibers::detail::scheduler::instance().active()->set_waiting(); - boost::fibers::detail::scheduler::instance().active()->suspend(); + boost::fibers::detail::scheduler::instance()->active()->set_waiting(); + boost::fibers::detail::scheduler::instance()->active()->suspend(); const basic_yield_context< Handler > yield( data->fiber_, data->handler_); ( data->function_)( yield); @@ -274,7 +274,7 @@ struct spawn_helper data_->fiber_ = boost::fibers::detail::scheduler::extract( fiber); fiber.detach(); data_->fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( data_->fiber_); + boost::fibers::detail::scheduler::instance()->spawn( data_->fiber_); } shared_ptr< spawn_data< Handler, Function > > data_; diff --git a/include/boost/fiber/asio/detail/use_future.hpp b/include/boost/fiber/asio/detail/use_future.hpp index 14e65b57..719efd12 100644 --- a/include/boost/fiber/asio/detail/use_future.hpp +++ b/include/boost/fiber/asio/detail/use_future.hpp @@ -52,7 +52,7 @@ public: void operator()( T t) { promise_->set_value( t); - boost::fibers::detail::scheduler::instance().run(); + boost::fibers::detail::scheduler::instance()->run(); } void operator()( boost::system::error_code const& ec, T t) @@ -66,7 +66,7 @@ public: // scheduler::run() resumes a ready fiber // invoke scheduler::run() until no fiber was resumed - while ( boost::fibers::detail::scheduler::instance().run() ); + while ( boost::fibers::detail::scheduler::instance()->run() ); } //private: @@ -88,7 +88,7 @@ public: void operator()() { promise_->set_value(); - boost::fibers::detail::scheduler::instance().run(); + boost::fibers::detail::scheduler::instance()->run(); } void operator()( boost::system::error_code const& ec) @@ -102,7 +102,7 @@ public: // scheduler::run() resumes a ready fiber // invoke scheduler::run() until no fiber was resumed - while ( boost::fibers::detail::scheduler::instance().run() ); + while ( boost::fibers::detail::scheduler::instance()->run() ); } //private: diff --git a/include/boost/fiber/asio/detail/yield.hpp b/include/boost/fiber/asio/detail/yield.hpp index f814ceab..cd861b88 100644 --- a/include/boost/fiber/asio/detail/yield.hpp +++ b/include/boost/fiber/asio/detail/yield.hpp @@ -24,7 +24,7 @@ class yield_handler { public: yield_handler( yield_t const& y) : - fiber_( boost::fibers::detail::scheduler::instance().active() ), + fiber_( boost::fibers::detail::scheduler::instance()->active() ), ec_( y.ec_), value_( 0) {} @@ -33,7 +33,7 @@ public: * ec_ = boost::system::error_code(); * value_ = t; fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } void operator()( boost::system::error_code const& ec, T t) @@ -41,7 +41,7 @@ public: * ec_ = ec; * value_ = t; fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } //private: @@ -56,7 +56,7 @@ class yield_handler< void > { public: yield_handler( yield_t const& y) : - fiber_( boost::fibers::detail::scheduler::instance().active() ), + fiber_( boost::fibers::detail::scheduler::instance()->active() ), ec_( y.ec_) {} @@ -64,14 +64,14 @@ public: { * ec_ = boost::system::error_code(); fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } void operator()( boost::system::error_code const& ec) { * ec_ = ec; fiber_->set_ready(); - boost::fibers::detail::scheduler::instance().spawn( fiber_); + boost::fibers::detail::scheduler::instance()->spawn( fiber_); } //private: @@ -102,8 +102,8 @@ public: type get() { - boost::fibers::detail::scheduler::instance().active()->set_waiting(); - boost::fibers::detail::scheduler::instance().active()->suspend(); + boost::fibers::detail::scheduler::instance()->active()->set_waiting(); + boost::fibers::detail::scheduler::instance()->active()->suspend(); if ( ! out_ec_ && ec_) throw_exception( boost::system::system_error( ec_) ); return value_; @@ -129,8 +129,8 @@ public: void get() { - boost::fibers::detail::scheduler::instance().active()->set_waiting(); - boost::fibers::detail::scheduler::instance().active()->suspend(); + boost::fibers::detail::scheduler::instance()->active()->set_waiting(); + boost::fibers::detail::scheduler::instance()->active()->suspend(); if ( ! out_ec_ && ec_) throw_exception( boost::system::system_error( ec_) ); } diff --git a/include/boost/fiber/asio/io_service.hpp b/include/boost/fiber/asio/io_service.hpp index e48819bb..ed61de35 100644 --- a/include/boost/fiber/asio/io_service.hpp +++ b/include/boost/fiber/asio/io_service.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke, Christopher M. Kohlhoff 2009. +// Copyright Oliver Kowalke, Christopher M. Kohlhoff 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) diff --git a/include/boost/fiber/attributes.hpp b/include/boost/fiber/attributes.hpp index 50c200c7..b000a578 100644 --- a/include/boost/fiber/attributes.hpp +++ b/include/boost/fiber/attributes.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/barrier.hpp b/include/boost/fiber/barrier.hpp index 49db34bc..bc4a618b 100644 --- a/include/boost/fiber/barrier.hpp +++ b/include/boost/fiber/barrier.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/bounded_queue.hpp b/include/boost/fiber/bounded_queue.hpp index 9950d58b..ae546a4a 100644 --- a/include/boost/fiber/bounded_queue.hpp +++ b/include/boost/fiber/bounded_queue.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index 09c25ba6..1b8b9aeb 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) @@ -62,7 +62,7 @@ public: template< typename LockType > void wait( LockType & lt) { - detail::notify::ptr_t n( detail::scheduler::instance().active() ); + detail::notify::ptr_t n( detail::scheduler::instance()->active() ); try { if ( n) @@ -72,7 +72,7 @@ public: lt.unlock(); // suspend fiber - detail::scheduler::instance().wait(); + detail::scheduler::instance()->wait(); // check if fiber was interrupted this_fiber::interruption_point(); @@ -90,7 +90,7 @@ public: while ( ! n->is_ready() ) { // run scheduler - detail::scheduler::instance().run(); + detail::scheduler::instance()->run(); } } } diff --git a/include/boost/fiber/detail/config.hpp b/include/boost/fiber/detail/config.hpp index 7c0a915f..31ba2d67 100644 --- a/include/boost/fiber/detail/config.hpp +++ b/include/boost/fiber/detail/config.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/fiber_base.hpp b/include/boost/fiber/detail/fiber_base.hpp index 36032501..d4766ac5 100644 --- a/include/boost/fiber/detail/fiber_base.hpp +++ b/include/boost/fiber/detail/fiber_base.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) @@ -9,11 +9,11 @@ #include #include +#include #include -#include +#include #include -#include #include #include #include @@ -22,6 +22,7 @@ #include #include #include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -37,7 +38,7 @@ struct forced_unwind {}; class BOOST_FIBERS_DECL fiber_base : public notify { public: - typedef intrusive_ptr< fiber_base > ptr_t; + typedef intrusive_ptr< fiber_base > ptr_t; private: enum state_t @@ -48,6 +49,29 @@ private: TERMINATED }; + struct fss_data + { + void * vp; + fss_cleanup_function::ptr_t cleanup_function; + + fss_data() : + vp( 0), cleanup_function( 0) + {} + + fss_data( + void * vp_, + fss_cleanup_function::ptr_t const& fn) : + vp( vp_), cleanup_function( fn) + { BOOST_ASSERT( cleanup_function); } + + void do_cleanup() + { ( * cleanup_function)( vp); } + }; + + typedef std::map< uintptr_t, fss_data > fss_data_t; + + fss_data_t fss_data_; + protected: state_t state_; int flags_; @@ -241,9 +265,10 @@ public: // - this fiber was interrupted and therefore resumed and // throws fiber_interrupted // - fiber_interrupted was catched and swallowed - // - other fiber calls set_ready() on this fiber happend before this - // fiber calls set_waiting() - // - this fiber might wait on some sync. primitive calling set_waiting() + // - other fiber calls set_ready() on this fiber happend before + // this fiber calls set_waiting() + // - this fiber might wait on some sync. primitive calling + // set_waiting() state_t previous = WAITING; std::swap( state_, previous); BOOST_ASSERT( RUNNING == previous); @@ -254,6 +279,14 @@ public: { return except_; } void rethrow() const; + + void * get_fss_data( void const* vp) const; + + void set_fss_data( + void const* vp, + fss_cleanup_function::ptr_t const& cleanup_fn, + void * data, + bool cleanup_existing); }; }}} diff --git a/include/boost/fiber/detail/fiber_context.hpp b/include/boost/fiber/detail/fiber_context.hpp index f3e114dc..6b17c6e6 100644 --- a/include/boost/fiber/detail/fiber_context.hpp +++ b/include/boost/fiber/detail/fiber_context.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/fiber_object.hpp b/include/boost/fiber/detail/fiber_object.hpp index f3ac8097..4f15105b 100644 --- a/include/boost/fiber/detail/fiber_object.hpp +++ b/include/boost/fiber/detail/fiber_object.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/flags.hpp b/include/boost/fiber/detail/flags.hpp index 4f6ab797..82e2031a 100644 --- a/include/boost/fiber/detail/flags.hpp +++ b/include/boost/fiber/detail/flags.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/interrupt_flags.hpp b/include/boost/fiber/detail/interrupt_flags.hpp index 29fc51b8..044a79d5 100644 --- a/include/boost/fiber/detail/interrupt_flags.hpp +++ b/include/boost/fiber/detail/interrupt_flags.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/main_notifier.hpp b/include/boost/fiber/detail/main_notifier.hpp index 1d161ddd..dfc367a3 100644 --- a/include/boost/fiber/detail/main_notifier.hpp +++ b/include/boost/fiber/detail/main_notifier.hpp @@ -1,4 +1,4 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/notify.hpp b/include/boost/fiber/detail/notify.hpp index 176c560e..b12247e4 100644 --- a/include/boost/fiber/detail/notify.hpp +++ b/include/boost/fiber/detail/notify.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/queue.hpp b/include/boost/fiber/detail/queue.hpp index 9eef3abb..00cb729d 100644 --- a/include/boost/fiber/detail/queue.hpp +++ b/include/boost/fiber/detail/queue.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/scheduler.hpp b/include/boost/fiber/detail/scheduler.hpp index b3adcf75..cfe2cc16 100644 --- a/include/boost/fiber/detail/scheduler.hpp +++ b/include/boost/fiber/detail/scheduler.hpp @@ -1,4 +1,4 @@ -// Copyright Oliver Kowalke 2009. +// 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) @@ -97,7 +97,7 @@ public: return f.impl_; } - static algorithm & instance() BOOST_NOEXCEPT; + static algorithm * instance() BOOST_NOEXCEPT; static algorithm * replace( algorithm *) BOOST_NOEXCEPT; }; diff --git a/include/boost/fiber/detail/segmented_stack_allocator.hpp b/include/boost/fiber/detail/segmented_stack_allocator.hpp index 659d62c3..8d17c8e8 100644 --- a/include/boost/fiber/detail/segmented_stack_allocator.hpp +++ b/include/boost/fiber/detail/segmented_stack_allocator.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/stack_tuple.hpp b/include/boost/fiber/detail/stack_tuple.hpp index 12ada34c..ec18c85f 100644 --- a/include/boost/fiber/detail/stack_tuple.hpp +++ b/include/boost/fiber/detail/stack_tuple.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/standard_stack_allocator.hpp b/include/boost/fiber/detail/standard_stack_allocator.hpp index 37ae721d..57112eb5 100644 --- a/include/boost/fiber/detail/standard_stack_allocator.hpp +++ b/include/boost/fiber/detail/standard_stack_allocator.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/detail/thread_yield.hpp b/include/boost/fiber/detail/thread_yield.hpp index acd9eece..b44931ec 100644 --- a/include/boost/fiber/detail/thread_yield.hpp +++ b/include/boost/fiber/detail/thread_yield.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/exceptions.hpp b/include/boost/fiber/exceptions.hpp index a4bd37f9..1ab964be 100644 --- a/include/boost/fiber/exceptions.hpp +++ b/include/boost/fiber/exceptions.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index fb4b3aac..fd09daf0 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) @@ -20,6 +20,7 @@ #include #include +#include #include #include #include diff --git a/include/boost/fiber/flags.hpp b/include/boost/fiber/flags.hpp index 5fb95e03..7a5eef88 100644 --- a/include/boost/fiber/flags.hpp +++ b/include/boost/fiber/flags.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future.hpp b/include/boost/fiber/future.hpp index 05c2d7a5..f552ce78 100644 --- a/include/boost/fiber/future.hpp +++ b/include/boost/fiber/future.hpp @@ -1,4 +1,4 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/detail/future_base.hpp b/include/boost/fiber/future/detail/future_base.hpp index 79176508..584ff4c0 100644 --- a/include/boost/fiber/future/detail/future_base.hpp +++ b/include/boost/fiber/future/detail/future_base.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/detail/future_object.hpp b/include/boost/fiber/future/detail/future_object.hpp index a20f61d6..62004bde 100644 --- a/include/boost/fiber/future/detail/future_object.hpp +++ b/include/boost/fiber/future/detail/future_object.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/detail/task_base.hpp b/include/boost/fiber/future/detail/task_base.hpp index 6773d8e9..f445a3d6 100644 --- a/include/boost/fiber/future/detail/task_base.hpp +++ b/include/boost/fiber/future/detail/task_base.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/detail/task_object.hpp b/include/boost/fiber/future/detail/task_object.hpp index f4c92bff..f21ae229 100644 --- a/include/boost/fiber/future/detail/task_object.hpp +++ b/include/boost/fiber/future/detail/task_object.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/future.hpp b/include/boost/fiber/future/future.hpp index e85a4037..fac04a6d 100644 --- a/include/boost/fiber/future/future.hpp +++ b/include/boost/fiber/future/future.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/packaged_task.hpp b/include/boost/fiber/future/packaged_task.hpp index 8659e734..98361a75 100644 --- a/include/boost/fiber/future/packaged_task.hpp +++ b/include/boost/fiber/future/packaged_task.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/future/promise.hpp b/include/boost/fiber/future/promise.hpp index 080a4f1d..421637cc 100644 --- a/include/boost/fiber/future/promise.hpp +++ b/include/boost/fiber/future/promise.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/interruption.hpp b/include/boost/fiber/interruption.hpp index 955424d5..2967cec5 100644 --- a/include/boost/fiber/interruption.hpp +++ b/include/boost/fiber/interruption.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/mutex.hpp b/include/boost/fiber/mutex.hpp index 0f0b7c5d..7173021b 100644 --- a/include/boost/fiber/mutex.hpp +++ b/include/boost/fiber/mutex.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 6e148851..640cdc59 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -1,4 +1,4 @@ -// Copyright Oliver Kowalke 2009. +// 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) @@ -20,14 +20,14 @@ namespace this_fiber { inline fibers::fiber::id get_id() { - return fibers::detail::scheduler::instance().active() - ? fibers::detail::scheduler::instance().active()->get_id() + return fibers::detail::scheduler::instance()->active() + ? fibers::detail::scheduler::instance()->active()->get_id() : fibers::fiber::id(); } inline void yield() -{ fibers::detail::scheduler::instance().yield(); } +{ fibers::detail::scheduler::instance()->yield(); } } diff --git a/include/boost/fiber/round_robin.hpp b/include/boost/fiber/round_robin.hpp index 36d97cc6..bcf27269 100644 --- a/include/boost/fiber/round_robin.hpp +++ b/include/boost/fiber/round_robin.hpp @@ -1,4 +1,4 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/stack_allocator.hpp b/include/boost/fiber/stack_allocator.hpp index 1c22e9c9..27eb1114 100644 --- a/include/boost/fiber/stack_allocator.hpp +++ b/include/boost/fiber/stack_allocator.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/stack_context.hpp b/include/boost/fiber/stack_context.hpp index aed41652..81c7f522 100644 --- a/include/boost/fiber/stack_context.hpp +++ b/include/boost/fiber/stack_context.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/include/boost/fiber/unbounded_queue.hpp b/include/boost/fiber/unbounded_queue.hpp index fd09aeb8..418e8105 100644 --- a/include/boost/fiber/unbounded_queue.hpp +++ b/include/boost/fiber/unbounded_queue.hpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/src/detail/fiber_base.cpp b/src/detail/fiber_base.cpp index 32854a7e..4a516ee3 100644 --- a/src/detail/fiber_base.cpp +++ b/src/detail/fiber_base.cpp @@ -25,6 +25,7 @@ namespace detail { fiber_base::fiber_base( fiber_context::ctx_fn fn, stack_context * stack_ctx, bool preserve_fpu) : + fss_data_(), state_( READY), flags_( 0), priority_( 0), @@ -73,6 +74,10 @@ fiber_base::release() // notify all waiting fibers BOOST_FOREACH( fiber_base::ptr_t p, waiting) { p->set_ready(); } + + // release all fiber-specific-pointers + BOOST_FOREACH( fss_data_t::value_type & data, fss_data_) + { data.second.do_cleanup(); } } bool @@ -92,6 +97,44 @@ fiber_base::rethrow() const rethrow_exception( except_); } +void * +fiber_base::get_fss_data( void const* vp) const +{ + uintptr_t key( reinterpret_cast< uintptr_t >( vp) ); + fss_data_t::const_iterator i( fss_data_.find( key) ); + + return fss_data_.end() != i ? i->second.vp : 0; +} + +void +fiber_base::set_fss_data( + void const* vp, + fss_cleanup_function::ptr_t const& cleanup_fn, + void * data, bool cleanup_existing) +{ + BOOST_ASSERT( cleanup_fn); + + uintptr_t key( reinterpret_cast< uintptr_t >( vp) ); + fss_data_t::iterator i( fss_data_.find( key) ); + + if ( fss_data_.end() != i) + { + if( cleanup_existing) i->second.do_cleanup(); + if ( data) + fss_data_.insert( + i, + std::make_pair( + key, + fss_data( data, cleanup_fn) ) ); + else fss_data_.erase( i); + } + else + fss_data_.insert( + std::make_pair( + key, + fss_data( data, cleanup_fn) ) ); +} + }}} #ifdef BOOST_HAS_ABI_HEADERS diff --git a/src/detail/scheduler.cpp b/src/detail/scheduler.cpp index 5e4bb105..5e8e2d9e 100644 --- a/src/detail/scheduler.cpp +++ b/src/detail/scheduler.cpp @@ -27,12 +27,9 @@ detail::thread_local_ptr scheduler::instance_ = 0; __thread algorithm * scheduler::instance_ = 0; #endif -algorithm & +algorithm * scheduler::instance() BOOST_NOEXCEPT -{ - BOOST_ASSERT( instance_); - return * instance_; -} +{ return instance_; } algorithm * scheduler::replace( algorithm * other) BOOST_NOEXCEPT diff --git a/src/fiber.cpp b/src/fiber.cpp index 0c9858c3..e51bea55 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -26,7 +26,7 @@ namespace fibers { void fiber::start_fiber_() -{ detail::scheduler::instance().spawn( impl_); } +{ detail::scheduler::instance()->spawn( impl_); } int fiber::priority() const BOOST_NOEXCEPT @@ -41,7 +41,7 @@ fiber::priority( int prio) BOOST_NOEXCEPT { BOOST_ASSERT( impl_); - detail::scheduler::instance().priority( impl_, prio); + detail::scheduler::instance()->priority( impl_, prio); } void @@ -62,7 +62,7 @@ fiber::join() } try - { detail::scheduler::instance().join( impl_); } + { detail::scheduler::instance()->join( impl_); } catch (...) { impl_.reset(); diff --git a/src/interruption.cpp b/src/interruption.cpp index 968e74b2..505de47d 100644 --- a/src/interruption.cpp +++ b/src/interruption.cpp @@ -25,40 +25,40 @@ namespace boost { namespace this_fiber { disable_interruption::disable_interruption() BOOST_NOEXCEPT : - set_( ( fibers::detail::scheduler::instance().active()->interruption_blocked() ) ) + set_( ( fibers::detail::scheduler::instance()->active()->interruption_blocked() ) ) { if ( ! set_) - fibers::detail::scheduler::instance().active()->interruption_blocked( true); + fibers::detail::scheduler::instance()->active()->interruption_blocked( true); } disable_interruption::~disable_interruption() BOOST_NOEXCEPT { if ( ! set_) - fibers::detail::scheduler::instance().active()->interruption_blocked( false); + fibers::detail::scheduler::instance()->active()->interruption_blocked( false); } restore_interruption::restore_interruption( disable_interruption & disabler) BOOST_NOEXCEPT : disabler_( disabler) { if ( ! disabler_.set_) - fibers::detail::scheduler::instance().active()->interruption_blocked( false); + fibers::detail::scheduler::instance()->active()->interruption_blocked( false); } restore_interruption::~restore_interruption() BOOST_NOEXCEPT { if ( ! disabler_.set_) - fibers::detail::scheduler::instance().active()->interruption_blocked( true); + fibers::detail::scheduler::instance()->active()->interruption_blocked( true); } bool interruption_enabled() BOOST_NOEXCEPT { - fibers::detail::fiber_base::ptr_t f( fibers::detail::scheduler::instance().active() ); + fibers::detail::fiber_base::ptr_t f( fibers::detail::scheduler::instance()->active() ); return f && f->interruption_enabled(); } bool interruption_requested() BOOST_NOEXCEPT { - fibers::detail::fiber_base::ptr_t f( fibers::detail::scheduler::instance().active() ); + fibers::detail::fiber_base::ptr_t f( fibers::detail::scheduler::instance()->active() ); if ( ! f) return false; return f->interruption_requested(); } @@ -67,7 +67,7 @@ void interruption_point() { if ( interruption_requested() && interruption_enabled() ) { - fibers::detail::scheduler::instance().active()->request_interruption( false); + fibers::detail::scheduler::instance()->active()->request_interruption( false); boost::throw_exception( fibers::fiber_interrupted() ); } } diff --git a/src/mutex.cpp b/src/mutex.cpp index 34187517..012bc14d 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -36,7 +36,7 @@ mutex::lock() { while ( LOCKED == state_) { - detail::notify::ptr_t n( detail::scheduler::instance().active() ); + detail::notify::ptr_t n( detail::scheduler::instance()->active() ); try { if ( n) @@ -45,7 +45,7 @@ mutex::lock() waiting_.push_back( n); // suspend this fiber - detail::scheduler::instance().wait(); + detail::scheduler::instance()->wait(); } else { @@ -60,7 +60,7 @@ mutex::lock() while ( ! n->is_ready() ) { // run scheduler - detail::scheduler::instance().run(); + detail::scheduler::instance()->run(); } } } diff --git a/src/round_robin.cpp b/src/round_robin.cpp index 4443fe3e..3d3b7d58 100644 --- a/src/round_robin.cpp +++ b/src/round_robin.cpp @@ -45,6 +45,8 @@ round_robin::~round_robin() BOOST_NOEXCEPT BOOST_FOREACH( detail::fiber_base::ptr_t const& p, wqueue_) { p->release(); } #endif + if ( detail::scheduler::instance() == this) + detail::scheduler::replace( 0); } void diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 52139093..a39413ea 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,6 +1,6 @@ # Boost.strand Library Tests Jamfile -# Copyright Oliver Kowalke 2009. +# 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) @@ -31,6 +31,7 @@ test-suite fibers : [ fiber-test test_unique_lock ] [ fiber-test test_lock ] [ fiber-test test_barrier ] + [ fiber-test test_fss ] [ fiber-test test_futures ] # [ fiber-test test_then ] ; diff --git a/test/test_barrier.cpp b/test/test_barrier.cpp index a7aba930..223614ad 100644 --- a/test/test_barrier.cpp +++ b/test/test_barrier.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/test/test_condition.cpp b/test/test_condition.cpp index f09e69e8..53c3e362 100644 --- a/test/test_condition.cpp +++ b/test/test_condition.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/test/test_fiber.cpp b/test/test_fiber.cpp index ad385ba6..302de6dd 100644 --- a/test/test_fiber.cpp +++ b/test/test_fiber.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/test/test_lock.cpp b/test/test_lock.cpp index 8bc303db..b834d7d6 100644 --- a/test/test_lock.cpp +++ b/test/test_lock.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/test/test_mutex.cpp b/test/test_mutex.cpp index 8a10d93f..47012c8d 100644 --- a/test/test_mutex.cpp +++ b/test/test_mutex.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/test/test_unique_lock.cpp b/test/test_unique_lock.cpp index 87828ab8..cf22c3c1 100644 --- a/test/test_unique_lock.cpp +++ b/test/test_unique_lock.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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) diff --git a/test/test_waitfor.cpp b/test/test_waitfor.cpp index 51c5d4ff..674fa5e4 100644 --- a/test/test_waitfor.cpp +++ b/test/test_waitfor.cpp @@ -1,5 +1,5 @@ -// Copyright Oliver Kowalke 2009. +// 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)