diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index 17bf7e9a..2f8b4d2d 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -72,7 +71,7 @@ public: template< typename LockType > void wait( LockType & lt) { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); try { if ( n) @@ -91,7 +90,7 @@ public: // suspend this fiber // locked spinlock will be released if this fiber // was stored inside schedulers's waiting-queue - fm_wait( detail::scheduler::instance(), lk); + fm_wait( lk); // this fiber was notified and resumed // check if fiber was interrupted @@ -123,7 +122,7 @@ public: // loop until main-notifier gets notified while ( ! n->is_ready() ) // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); // lock external again before returning lt.lock(); @@ -144,7 +143,7 @@ public: { cv_status status = cv_status::no_timeout; - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); try { if ( n) @@ -162,7 +161,7 @@ public: // suspend this fiber // locked spinlock will be released if this fiber // was stored inside schedulers's waiting-queue - if ( ! fm_wait_until( detail::scheduler::instance(), timeout_time, lk) ) + if ( ! fm_wait_until( timeout_time, lk) ) { // this fiber was not notified before timeout // lock spinlock again @@ -216,7 +215,7 @@ public: break; } // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } // lock external again before returning diff --git a/include/boost/fiber/detail/scheduler.hpp b/include/boost/fiber/detail/scheduler.hpp index 8f12ce7b..a2b883ad 100644 --- a/include/boost/fiber/detail/scheduler.hpp +++ b/include/boost/fiber/detail/scheduler.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -40,22 +41,31 @@ private: #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) || \ (defined(__ICC) && defined(BOOST_WINDOWS)) - static volatile __declspec(thread) T * t_; + __declspec(thread) T * t_; #elif defined(__APPLE__) && defined(BOOST_HAS_PTHREADS) - static volatile detail::thread_local_ptr< T > t_; + // TODO: fixme + detail::thread_local_ptr< T > t_; #else - static volatile __thread T * t_; + T * t_; #endif - cleanup_function cf_; + cleanup_function cf_; public: thread_local_ptr( cleanup_function cf) BOOST_NOEXCEPT : +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) || \ + (defined(__ICC) && defined(BOOST_WINDOWS)) + t_( 0), +#elif defined(__APPLE__) && defined(BOOST_HAS_PTHREADS) + t_(), +#else + t_( 0), +#endif cf_( cf) {} BOOST_EXPLICIT_OPERATOR_BOOL(); - volatile T * get() const BOOST_NOEXCEPT volatile + T * get() const BOOST_NOEXCEPT { return t_; } bool operator!() const BOOST_NOEXCEPT @@ -67,21 +77,21 @@ public: bool operator!=( thread_local_ptr const& other) BOOST_NOEXCEPT { return ! ( * this == other); } - void reset( T * t) BOOST_NOEXCEPT volatile + void reset( T * t) BOOST_NOEXCEPT { t_ = t; } }; class scheduler : private noncopyable { private: - static volatile thread_local_ptr< fiber_manager > instance_; + static thread_specific_ptr< fiber_manager > instance_; public: template< typename F > static worker_fiber * extract( F const& f) BOOST_NOEXCEPT { return f.impl_; } - static volatile fiber_manager * instance() + static fiber_manager * instance() { if ( ! instance_.get() ) instance_.reset( new fiber_manager() ); diff --git a/include/boost/fiber/fiber_manager.hpp b/include/boost/fiber/fiber_manager.hpp index 595a2c2e..7105d567 100644 --- a/include/boost/fiber/fiber_manager.hpp +++ b/include/boost/fiber/fiber_manager.hpp @@ -52,82 +52,48 @@ struct fiber_manager : private noncopyable scoped_ptr< sched_algorithm > def_algo_; sched_algorithm * sched_algo_; - volatile wqueue_t wqueue_; + wqueue_t wqueue_; clock_type::duration wait_interval_; detail::worker_fiber * active_fiber_; }; -void fm_resume_( volatile fiber_manager *, detail:: worker_fiber *); +void fm_resume_( detail::worker_fiber *); -inline -void fm_set_sched_algo( volatile fiber_manager * fm, sched_algorithm * algo) -{ - BOOST_ASSERT( fm); - - fm->sched_algo_ = algo; - //fm->def_algo_.reset(); -} +void fm_set_sched_algo( sched_algorithm *); -void fm_spawn( volatile fiber_manager *, detail::worker_fiber *); +void fm_spawn( detail::worker_fiber *); -inline -void fm_priority( volatile fiber_manager * fm, detail::worker_fiber * f, - int prio) BOOST_NOEXCEPT -{ - BOOST_ASSERT( fm); - - fm->sched_algo_->priority( f, prio); -} +void fm_priority( detail::worker_fiber *, int) BOOST_NOEXCEPT; +void fm_wait_interval( clock_type::duration const&) BOOST_NOEXCEPT; template< typename Rep, typename Period > -void fm_wait_interval( volatile fiber_manager * fm, - chrono::duration< Rep, Period > const& wait_interval) BOOST_NOEXCEPT -{ - BOOST_ASSERT( fm); - - fm->wait_interval_ = wait_interval; -} +void fm_wait_interval( chrono::duration< Rep, Period > const& wait_interval) BOOST_NOEXCEPT +{ fm_wait_interval( wait_interval); } -template< typename Rep, typename Period > -chrono::duration< Rep, Period > fm_wait_interval( volatile fiber_manager * fm) BOOST_NOEXCEPT -{ - BOOST_ASSERT( fm); - - return fm->wait_interval_; -} +clock_type::duration fm_wait_interval() BOOST_NOEXCEPT; -void fm_join( volatile fiber_manager *, detail::worker_fiber *); +void fm_join( detail::worker_fiber *); -inline -detail::worker_fiber * fm_active( volatile fiber_manager * fm) BOOST_NOEXCEPT -{ - BOOST_ASSERT( fm); - - return fm->active_fiber_; -} +detail::worker_fiber * fm_active() BOOST_NOEXCEPT; -void fm_run( volatile fiber_manager *); +void fm_run(); -void fm_wait( volatile fiber_manager *, unique_lock< detail::spinlock > &); -bool fm_wait_until( volatile fiber_manager *, - clock_type::time_point const&, +void fm_wait( unique_lock< detail::spinlock > &); +bool fm_wait_until( clock_type::time_point const&, unique_lock< detail::spinlock > &); template< typename Rep, typename Period > -bool fm_wait_for( volatile fiber_manager * fm, - chrono::duration< Rep, Period > const& timeout_duration, +bool fm_wait_for( chrono::duration< Rep, Period > const& timeout_duration, unique_lock< detail::spinlock > & lk) { - BOOST_ASSERT( fm); - - return wait_until( fm, clock_type::now() + timeout_duration, lk); + return wait_until( clock_type::now() + timeout_duration, lk); } -void fm_yield( volatile fiber_manager *); +void fm_yield(); -clock_type::time_point fm_next_wakeup( volatile fiber_manager *); +clock_type::time_point fm_next_wakeup(); -void fm_migrate( volatile fiber_manager *, detail::worker_fiber *); +void fm_migrate( detail::worker_fiber *); }} diff --git a/include/boost/fiber/fss.hpp b/include/boost/fiber/fss.hpp index c331265e..1ab562a4 100644 --- a/include/boost/fiber/fss.hpp +++ b/include/boost/fiber/fss.hpp @@ -16,7 +16,6 @@ #include #include -#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -62,16 +61,16 @@ public: ~fiber_specific_ptr() { - if ( fm_active( detail::scheduler::instance() ) ) - fm_active( detail::scheduler::instance() )->set_fss_data( + if ( fm_active() ) + fm_active()->set_fss_data( this, cleanup_fn_, 0, true); } T * get() const { - BOOST_ASSERT( fm_active( detail::scheduler::instance() ) ); + BOOST_ASSERT( fm_active() ); - void * vp( fm_active( detail::scheduler::instance() )->get_fss_data( this) ); + void * vp( fm_active()->get_fss_data( this) ); return static_cast< T * >( vp); } @@ -84,7 +83,7 @@ public: T * release() { T * tmp = get(); - fm_active( detail::scheduler::instance() )->set_fss_data( + fm_active()->set_fss_data( this, cleanup_fn_, 0, false); return tmp; } @@ -93,7 +92,7 @@ public: { T * c = get(); if ( c != t) - fm_active( detail::scheduler::instance() )->set_fss_data( + fm_active()->set_fss_data( this, cleanup_fn_, t, true); } }; diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 3db9ab54..1fdc06ec 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -25,28 +25,28 @@ namespace this_fiber { inline fibers::fiber::id get_id() BOOST_NOEXCEPT { - return 0 != fibers::fm_active( fibers::detail::scheduler::instance() ) - ? fibers::fm_active( fibers::detail::scheduler::instance() )->get_id() + return 0 != fibers::fm_active() + ? fibers::fm_active()->get_id() : fibers::fiber::id(); } inline void yield() { - if ( 0 != fibers::fm_active( fibers::detail::scheduler::instance() ) ) - fibers::fm_yield( fibers::detail::scheduler::instance() ); + if ( 0 != fibers::fm_active() ) + fibers::fm_yield(); else - fibers::fm_run( fibers::detail::scheduler::instance() ); + fibers::fm_run(); } inline void sleep_until( fibers::clock_type::time_point const& sleep_time) { - if ( 0 != fibers::fm_active( fibers::detail::scheduler::instance() ) ) + if ( 0 != fibers::fm_active() ) { fibers::detail::spinlock splk; unique_lock< fibers::detail::spinlock > lk( splk); - fibers::fm_wait_until( fibers::detail::scheduler::instance(), sleep_time, lk); + fibers::fm_wait_until( sleep_time, lk); // check if fiber was interrupted interruption_point(); @@ -54,7 +54,7 @@ void sleep_until( fibers::clock_type::time_point const& sleep_time) else { while ( fibers::clock_type::now() <= sleep_time) - fibers::fm_run( fibers::detail::scheduler::instance() ); + fibers::fm_run(); } } @@ -65,16 +65,16 @@ void sleep_for( chrono::duration< Rep, Period > const& timeout_duration) inline bool thread_affinity() BOOST_NOEXCEPT { - return 0 != fibers::fm_active( fibers::detail::scheduler::instance() ) - ? fibers::fm_active( fibers::detail::scheduler::instance() )->thread_affinity() + return 0 != fibers::fm_active() + ? fibers::fm_active()->thread_affinity() : true; } inline void thread_affinity( bool req) BOOST_NOEXCEPT { - if ( 0 != fibers::fm_active( fibers::detail::scheduler::instance() ) ) - fibers::fm_active( fibers::detail::scheduler::instance() )->thread_affinity( req); + if ( 0 != fibers::fm_active() ) + fibers::fm_active()->thread_affinity( req); } } @@ -87,15 +87,15 @@ void set_scheduling_algorithm( sched_algorithm * al) template< typename Rep, typename Period > void set_wait_interval( chrono::duration< Rep, Period > const& wait_interval) BOOST_NOEXCEPT -{ fm_wait_interval( fibers::detail::scheduler::instance(), wait_interval); } +{ fm_wait_interval( wait_interval); } template< typename Rep, typename Period > chrono::duration< Rep, Period > get_wait_interval() BOOST_NOEXCEPT -{ return fm_wait_interval< Rep, Period >( fibers::detail::scheduler::instance() ); } +{ return fm_wait_interval< Rep, Period >(); } inline void migrate( fiber const& f) -{ fm_migrate( fibers::detail::scheduler::instance(), detail::scheduler::extract( f ) ); } +{ fm_migrate( detail::scheduler::extract( f ) ); } }} diff --git a/src/condition.cpp b/src/condition.cpp index 4e0fa82d..6b624346 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -8,8 +8,6 @@ #include -#include "boost/fiber/detail/scheduler.hpp" - #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX #endif diff --git a/src/detail/scheduler.cpp b/src/detail/scheduler.cpp index 96af8322..310bc3e4 100644 --- a/src/detail/scheduler.cpp +++ b/src/detail/scheduler.cpp @@ -7,6 +7,8 @@ #include +#include + #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX #endif @@ -17,26 +19,14 @@ namespace detail { static void deleter_fn( fiber_manager * mgr) { delete mgr; } -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) || \ - (defined(__ICC) && defined(BOOST_WINDOWS)) -template< typename T > -volatile __declspec(thread) T * thread_local_ptr< T >::t_ = 0; -#elif defined(__APPLE__) && defined(BOOST_HAS_PTHREADS) -template< typename T > -volatile detail::thread_local_ptr< T > thread_local_ptr< T >::t_; -#else -template< typename T > -volatile __thread T * thread_local_ptr< T >::t_ = 0; -#endif - -volatile thread_local_ptr< fiber_manager > scheduler::instance_( deleter_fn); +thread_specific_ptr< fiber_manager > scheduler::instance_( deleter_fn); void scheduler::replace( sched_algorithm * other) { BOOST_ASSERT( other); - fm_set_sched_algo( instance(), other); + fm_set_sched_algo( other); } }}} diff --git a/src/detail/spinlock.cpp b/src/detail/spinlock.cpp index 0e070945..d999f25f 100644 --- a/src/detail/spinlock.cpp +++ b/src/detail/spinlock.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include namespace boost { namespace fibers { @@ -22,7 +22,6 @@ spinlock::spinlock() : void spinlock::lock() { - bool is_fiber = 0 != fm_active( scheduler::instance() ); for (;;) { // access to CPU's cache @@ -31,8 +30,8 @@ spinlock::lock() while ( LOCKED == state_) { // busy-wait - if ( is_fiber) - fm_yield( scheduler::instance() ); + if ( 0 != fm_active() ) + fm_yield(); else this_thread::yield(); } diff --git a/src/fiber.cpp b/src/fiber.cpp index e4006f37..614530dd 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -11,7 +11,6 @@ #include #include -#include "boost/fiber/detail/scheduler.hpp" #include "boost/fiber/exceptions.hpp" #include "boost/fiber/operations.hpp" @@ -26,7 +25,7 @@ void fiber::start_fiber_() { impl_->set_ready(); - fm_spawn( detail::scheduler::instance(), impl_); + fm_spawn( impl_); } int @@ -42,7 +41,7 @@ fiber::priority( int prio) BOOST_NOEXCEPT { BOOST_ASSERT( impl_); - fm_priority( detail::scheduler::instance(), impl_, prio); + fm_priority( impl_, prio); } bool @@ -78,7 +77,7 @@ fiber::join() system::errc::invalid_argument, "boost fiber: fiber not joinable") ); } - fm_join( detail::scheduler::instance(), impl_); + fm_join( impl_); detail::worker_fiber * tmp = 0; std::swap( tmp, impl_); diff --git a/src/fiber_manager.cpp b/src/fiber_manager.cpp index add0599e..9da49da6 100644 --- a/src/fiber_manager.cpp +++ b/src/fiber_manager.cpp @@ -61,11 +61,13 @@ fiber_manager::~fiber_manager() BOOST_NOEXCEPT //fm->active_fiber_->set_terminated(); while ( ! wqueue_.empty() ) - fm_run( this); + fm_run(); } -void fm_resume_( volatile fiber_manager * fm, detail::worker_fiber * f) +void fm_resume_( detail::worker_fiber * f) { + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); BOOST_ASSERT( f); BOOST_ASSERT( f->is_ready() ); @@ -83,16 +85,34 @@ void fm_resume_( volatile fiber_manager * fm, detail::worker_fiber * f) { // resume active-fiber == start or yield to fm->active_fiber_->resume( tmp); + // get instance of fiber_manager + // because fiber might be migrated + // to another thread + fm = detail::scheduler::instance(); if ( fm->active_fiber_->detached() && fm->active_fiber_->is_terminated() ) fm->active_fiber_->deallocate(); // reset active fiber to previous fm->active_fiber_ = tmp; + if ( 0 != fm->active_fiber_ && ! fm->active_fiber_->is_running() ) + fm->active_fiber_->set_running(); } } -clock_type::time_point fm_next_wakeup( volatile fiber_manager * fm) +void fm_set_sched_algo( sched_algorithm * algo) { + fiber_manager * fm = detail::scheduler::instance(); + + BOOST_ASSERT( fm); + + fm->sched_algo_ = algo; + fm->def_algo_.reset(); +} + +clock_type::time_point fm_next_wakeup() +{ + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); if ( fm->wqueue_.empty() ) @@ -106,8 +126,10 @@ clock_type::time_point fm_next_wakeup( volatile fiber_manager * fm) } } -void fm_spawn( volatile fiber_manager * fm, detail::worker_fiber * f) +void fm_spawn( detail::worker_fiber * f) { + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); BOOST_ASSERT( f); BOOST_ASSERT( f->is_ready() ); @@ -115,8 +137,38 @@ void fm_spawn( volatile fiber_manager * fm, detail::worker_fiber * f) fm->sched_algo_->awakened( f); } -void fm_run( volatile fiber_manager * fm) +void fm_priority( detail::worker_fiber * f, + int prio) BOOST_NOEXCEPT { + fiber_manager * fm = detail::scheduler::instance(); + + BOOST_ASSERT( fm); + + fm->sched_algo_->priority( f, prio); +} + +void fm_wait_interval( clock_type::duration const& wait_interval) BOOST_NOEXCEPT +{ + fiber_manager * fm = detail::scheduler::instance(); + + BOOST_ASSERT( fm); + + fm->wait_interval_ = wait_interval; +} + +clock_type::duration fm_wait_interval() BOOST_NOEXCEPT +{ + fiber_manager * fm = detail::scheduler::instance(); + + BOOST_ASSERT( fm); + + return fm->wait_interval_; +} + +void fm_run() +{ + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); for (;;) @@ -131,7 +183,7 @@ void fm_run( volatile fiber_manager * fm) if ( f) { BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); - fm_resume_( fm, f); + fm_resume_( f); return; } else @@ -142,7 +194,7 @@ void fm_run( volatile fiber_manager * fm) { // no fibers ready to run; the thread should sleep // until earliest fiber is scheduled to run - clock_type::time_point wakeup( fm_next_wakeup( fm) ); + clock_type::time_point wakeup( fm_next_wakeup() ); this_thread::sleep_until( wakeup); } return; @@ -150,17 +202,16 @@ void fm_run( volatile fiber_manager * fm) } } -void fm_wait( volatile fiber_manager * fm, unique_lock< detail::spinlock > & lk) +void fm_wait( unique_lock< detail::spinlock > & lk) { - BOOST_ASSERT( fm); - - fm_wait_until( fm, clock_type::time_point( (clock_type::duration::max)() ), lk); + fm_wait_until( clock_type::time_point( (clock_type::duration::max)() ), lk); } -bool fm_wait_until( volatile fiber_manager * fm, - clock_type::time_point const& timeout_time, +bool fm_wait_until( clock_type::time_point const& timeout_time, unique_lock< detail::spinlock > & lk) { + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); clock_type::time_point start( clock_type::now() ); @@ -176,13 +227,15 @@ bool fm_wait_until( volatile fiber_manager * fm, fm->active_fiber_->time_point( timeout_time); fm->wqueue_.push( fm->active_fiber_); // run next fiber - fm_run( fm); + fm_run(); return clock_type::now() < timeout_time; } -void fm_yield( volatile fiber_manager * fm) +void fm_yield() { + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); BOOST_ASSERT( fm->active_fiber_); BOOST_ASSERT( fm->active_fiber_->is_running() ); @@ -192,11 +245,13 @@ void fm_yield( volatile fiber_manager * fm) // push active fiber to scheduler-algo fm->sched_algo_->awakened( fm->active_fiber_); // run next fiber - fm_run( fm); + fm_run(); } -void fm_join( volatile fiber_manager * fm, detail::worker_fiber * f) +void fm_join( detail::worker_fiber * f) { + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); BOOST_ASSERT( f); BOOST_ASSERT( f != fm->active_fiber_); @@ -214,27 +269,35 @@ void fm_join( volatile fiber_manager * fm, detail::worker_fiber * f) // FIXME: better state_running and no suspend fm->active_fiber_->set_ready(); // run next fiber - fm_run( fm); + fm_run(); } else { while ( ! f->is_terminated() ) // yield this thread if scheduler did not // resumed some fibers in the previous round - fm_run( fm); + fm_run(); } BOOST_ASSERT( f->is_terminated() ); } -void fm_migrate( volatile fiber_manager * fm, detail::worker_fiber * f) +detail::worker_fiber * fm_active() BOOST_NOEXCEPT { + fiber_manager * fm = detail::scheduler::instance(); + BOOST_ASSERT( fm); + + return fm->active_fiber_; +} + +void fm_migrate( detail::worker_fiber * f) +{ BOOST_ASSERT( f); BOOST_ASSERT( f->is_ready() ); - fm_spawn( fm, f); - fm_run( fm); + fm_spawn( f); + fm_run(); } }} diff --git a/src/interruption.cpp b/src/interruption.cpp index 6ce4b373..0a06b212 100644 --- a/src/interruption.cpp +++ b/src/interruption.cpp @@ -11,7 +11,7 @@ #include #include "boost/fiber/detail/interrupt_flags.hpp" -#include "boost/fiber/detail/scheduler.hpp" +#include "boost/fiber/fiber_manager.hpp" #include "boost/fiber/exceptions.hpp" #include "boost/fiber/operations.hpp" @@ -23,40 +23,40 @@ namespace boost { namespace this_fiber { disable_interruption::disable_interruption() BOOST_NOEXCEPT : - set_( ( fm_active( fibers::detail::scheduler::instance() )->interruption_blocked() ) ) + set_( ( fibers::fm_active()->interruption_blocked() ) ) { if ( ! set_) - fm_active( fibers::detail::scheduler::instance() )->interruption_blocked( true); + fibers::fm_active()->interruption_blocked( true); } disable_interruption::~disable_interruption() BOOST_NOEXCEPT { if ( ! set_) - fm_active( fibers::detail::scheduler::instance() )->interruption_blocked( false); + fibers::fm_active()->interruption_blocked( false); } restore_interruption::restore_interruption( disable_interruption & disabler) BOOST_NOEXCEPT : disabler_( disabler) { if ( ! disabler_.set_) - fm_active( fibers::detail::scheduler::instance() )->interruption_blocked( false); + fibers::fm_active()->interruption_blocked( false); } restore_interruption::~restore_interruption() BOOST_NOEXCEPT { if ( ! disabler_.set_) - fm_active( fibers::detail::scheduler::instance() )->interruption_blocked( true); + fibers::fm_active()->interruption_blocked( true); } bool interruption_enabled() BOOST_NOEXCEPT { - fibers::detail::worker_fiber * f = fm_active( fibers::detail::scheduler::instance() ); + fibers::detail::worker_fiber * f = fibers::fm_active(); return 0 != f && ! f->interruption_blocked(); } bool interruption_requested() BOOST_NOEXCEPT { - fibers::detail::worker_fiber * f = fm_active( fibers::detail::scheduler::instance() ); + fibers::detail::worker_fiber * f = fibers::fm_active(); if ( 0 == f) return false; return f->interruption_requested(); } @@ -65,7 +65,7 @@ void interruption_point() { if ( interruption_requested() && interruption_enabled() ) { - fm_active( fibers::detail::scheduler::instance() )->request_interruption( false); + fibers::fm_active()->request_interruption( false); boost::throw_exception( fibers::fiber_interrupted() ); } } diff --git a/src/mutex.cpp b/src/mutex.cpp index e4acc2cb..dcfce3ea 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -10,7 +10,6 @@ #include -#include "boost/fiber/detail/scheduler.hpp" #include "boost/fiber/interruption.hpp" #include "boost/fiber/operations.hpp" @@ -37,7 +36,7 @@ mutex::~mutex() void mutex::lock() { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); if ( 0 != n) { for (;;) @@ -57,7 +56,7 @@ mutex::lock() waiting_.push_back( n); // suspend this fiber - fm_wait( detail::scheduler::instance(), lk); + fm_wait( lk); } } else @@ -86,7 +85,7 @@ mutex::lock() // wait until main-fiber gets notified while ( ! n->is_ready() ) // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } } } diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp index b32a9690..cca63ebf 100644 --- a/src/recursive_mutex.cpp +++ b/src/recursive_mutex.cpp @@ -10,7 +10,6 @@ #include -#include "boost/fiber/detail/scheduler.hpp" #include "boost/fiber/interruption.hpp" #include "boost/fiber/operations.hpp" @@ -39,7 +38,7 @@ recursive_mutex::~recursive_mutex() void recursive_mutex::lock() { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); if ( 0 != n) { for (;;) @@ -65,7 +64,7 @@ recursive_mutex::lock() waiting_.push_back( n); // suspend this fiber - fm_wait( detail::scheduler::instance(), lk); + fm_wait( lk); } } else @@ -100,7 +99,7 @@ recursive_mutex::lock() // wait until main-fiber gets notified while ( ! n->is_ready() ) // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } } } diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp index 3342b37d..f977be7a 100644 --- a/src/recursive_timed_mutex.cpp +++ b/src/recursive_timed_mutex.cpp @@ -10,7 +10,6 @@ #include -#include "boost/fiber/detail/scheduler.hpp" #include "boost/fiber/interruption.hpp" #include "boost/fiber/operations.hpp" @@ -39,7 +38,7 @@ recursive_timed_mutex::~recursive_timed_mutex() void recursive_timed_mutex::lock() { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); if ( 0 != n) { for (;;) @@ -65,7 +64,7 @@ recursive_timed_mutex::lock() waiting_.push_back( n); // suspend this fiber - fm_wait( detail::scheduler::instance(), lk); + fm_wait( lk); } } else @@ -100,7 +99,7 @@ recursive_timed_mutex::lock() // wait until main-fiber gets notified while ( ! n->is_ready() ) // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } } } @@ -135,7 +134,7 @@ recursive_timed_mutex::try_lock() bool recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); if ( n) { for (;;) @@ -164,7 +163,7 @@ recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_tim waiting_.push_back( n); // suspend this fiber until notified or timed-out - if ( ! fm_wait_until( detail::scheduler::instance(), timeout_time, lk) ) + if ( ! fm_wait_until( timeout_time, lk) ) { lk.lock(); // remove fiber from waiting-list @@ -220,7 +219,7 @@ recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_tim return false; } // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } } } diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp index 65b0727f..ec218d4e 100644 --- a/src/timed_mutex.cpp +++ b/src/timed_mutex.cpp @@ -10,7 +10,6 @@ #include -#include "boost/fiber/detail/scheduler.hpp" #include "boost/fiber/interruption.hpp" #include "boost/fiber/operations.hpp" @@ -37,7 +36,7 @@ timed_mutex::~timed_mutex() void timed_mutex::lock() { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); if ( n) { for (;;) @@ -57,7 +56,7 @@ timed_mutex::lock() waiting_.push_back( n); // suspend this fiber - fm_wait( detail::scheduler::instance(), lk); + fm_wait( lk); } } else @@ -86,7 +85,7 @@ timed_mutex::lock() // wait until main-fiber gets notified while ( ! n->is_ready() ) // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } } } @@ -115,7 +114,7 @@ timed_mutex::try_lock() bool timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) { - detail::fiber_base * n( fm_active( detail::scheduler::instance() ) ); + detail::fiber_base * n( fm_active() ); if ( n) { for (;;) @@ -138,7 +137,7 @@ timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) waiting_.push_back( n); // suspend this fiber until notified or timed-out - if ( ! fm_wait_until( detail::scheduler::instance(), timeout_time, lk) ) + if ( ! fm_wait_until( timeout_time, lk) ) { lk.lock(); // remove fiber from waiting-list @@ -188,7 +187,7 @@ timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) return false; } // run scheduler - fm_run( detail::scheduler::instance() ); + fm_run(); } } }