diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 9e9de10c..44647f38 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -31,7 +31,6 @@ lib boost_fiber : barrier.cpp condition.cpp detail/fifo.cpp - detail/scheduler.cpp detail/spinlock.cpp detail/waiting_queue.cpp fiber.cpp diff --git a/examples/futures_mt.cpp b/examples/futures_mt.cpp index 418d4317..aaa012ef 100644 --- a/examples/futures_mt.cpp +++ b/examples/futures_mt.cpp @@ -67,5 +67,7 @@ int main( int argc, char * argv[]) std::cout << "result == " << result << std::endl; } + std::cout << "done." << std::endl; + return 0; } diff --git a/examples/segmented_stack.cpp b/examples/segmented_stack.cpp index 0f96c621..872dffd2 100644 --- a/examples/segmented_stack.cpp +++ b/examples/segmented_stack.cpp @@ -62,5 +62,7 @@ int main( int argc, char * argv[]) std::thread( thread_fn).join(); + std::cout << "done." << std::endl; + return 0; } diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index 43e8cadb..6feca7c1 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -62,7 +62,7 @@ public: template< typename LockType > void wait( LockType & lt) { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); try { // lock spinlock std::unique_lock< detail::spinlock > lk( splk_); @@ -78,7 +78,7 @@ public: // suspend this fiber // locked spinlock will be released if this fiber // was stored inside schedulers's waiting-queue - fm_wait( lk); + detail::scheduler::instance()->wait( lk); // this fiber was notified and resumed // check if fiber was interrupted @@ -102,7 +102,7 @@ public: cv_status status = cv_status::no_timeout; std::chrono::high_resolution_clock::time_point timeout_time( detail::convert_tp( timeout_time_) ); - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); try { // lock spinlock std::unique_lock< detail::spinlock > lk( splk_); @@ -117,7 +117,7 @@ public: // suspend this fiber // locked spinlock will be released if this fiber // was stored inside schedulers's waiting-queue - if ( ! fm_wait_until( timeout_time, lk) ) { + if ( ! detail::scheduler::instance()->wait_until( timeout_time, lk) ) { // this fiber was not notified before timeout // lock spinlock again std::unique_lock< detail::spinlock > lk( splk_); diff --git a/include/boost/fiber/detail/scheduler.hpp b/include/boost/fiber/detail/scheduler.hpp index 30ed05eb..a610acf0 100644 --- a/include/boost/fiber/detail/scheduler.hpp +++ b/include/boost/fiber/detail/scheduler.hpp @@ -6,9 +6,11 @@ #ifndef BOOST_FIBERS_DETAIL_SCHEDULER_H #define BOOST_FIBERS_DETAIL_SCHEDULER_H +#include #include #include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -32,9 +34,16 @@ struct scheduler { return const_cast< F & >( f).impl_.get(); } - static fiber_manager * instance() noexcept; + static fiber_manager * instance() noexcept { + static thread_local fiber_manager mgr; + return & mgr; + } - static void replace( sched_algorithm *); + static void replace( sched_algorithm * other) { + BOOST_ASSERT( nullptr != other); + + instance()->set_sched_algo( other); + } }; }}} diff --git a/include/boost/fiber/fiber_context.hpp b/include/boost/fiber/fiber_context.hpp index 44654b14..4623a9c5 100644 --- a/include/boost/fiber/fiber_context.hpp +++ b/include/boost/fiber/fiber_context.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -123,7 +124,7 @@ private: release(); // switch to another fiber - fm_run(); + detail::scheduler::instance()->run(); BOOST_ASSERT_MSG( false, "fiber already terminated"); }), diff --git a/include/boost/fiber/fiber_manager.hpp b/include/boost/fiber/fiber_manager.hpp index 8eaa19b6..ca836387 100644 --- a/include/boost/fiber/fiber_manager.hpp +++ b/include/boost/fiber/fiber_manager.hpp @@ -29,6 +29,20 @@ class fiber_context; struct sched_algorithm; struct fiber_manager { +private: + typedef detail::waiting_queue wqueue_t; + typedef detail::fifo tqueue_t; + + sched_algorithm * sched_algo_; + fiber_context * active_fiber_; + wqueue_t wqueue_; + tqueue_t tqueue_; + bool preserve_fpu_; + std::chrono::high_resolution_clock::duration wait_interval_; + + void resume_( fiber_context *); + +public: fiber_manager() noexcept; fiber_manager( fiber_manager const&) = delete; @@ -36,65 +50,53 @@ struct fiber_manager { virtual ~fiber_manager() noexcept; - typedef detail::waiting_queue wqueue_t; - typedef detail::fifo tqueue_t; + std::chrono::high_resolution_clock::time_point next_wakeup(); - sched_algorithm * sched_algo; - fiber_context * active_fiber; - wqueue_t wqueue; - tqueue_t tqueue; - bool preserve_fpu; - std::chrono::high_resolution_clock::duration wait_interval; + void spawn( fiber_context *); + + void run(); + + void wait( std::unique_lock< detail::spinlock > &); + + bool wait_until( std::chrono::high_resolution_clock::time_point const&, + std::unique_lock< detail::spinlock > &); + + template< typename Clock, typename Duration > + bool wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time_, + std::unique_lock< detail::spinlock > & lk) { + std::chrono::high_resolution_clock::time_point timeout_time( + detail::convert_tp( timeout_time_) ); + return wait_until( timeout_time, lk); + } + + template< typename Rep, typename Period > + bool wait_for( std::chrono::duration< Rep, Period > const& timeout_duration, + std::unique_lock< detail::spinlock > & lk) { + return wait_until( std::chrono::high_resolution_clock::now() + timeout_duration, lk); + } + + void yield(); + + void join( fiber_context *); + + fiber_context * active() noexcept; + + void set_sched_algo( sched_algorithm *); + + void wait_interval( std::chrono::high_resolution_clock::duration const&) noexcept; + + template< typename Rep, typename Period > + void wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { + wait_interval( wait_interval); + } + + std::chrono::high_resolution_clock::duration wait_interval() noexcept; + + bool preserve_fpu(); + + void preserve_fpu( bool); }; -void fm_resume_( fiber_context *); - -std::chrono::high_resolution_clock::time_point fm_next_wakeup(); - -void fm_spawn( fiber_context *); - -void fm_run(); - -void fm_wait( std::unique_lock< detail::spinlock > &); - -bool fm_wait_until( std::chrono::high_resolution_clock::time_point const&, - std::unique_lock< detail::spinlock > &); - -template< typename Clock, typename Duration > -bool fm_wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time_, - std::unique_lock< detail::spinlock > & lk) { - std::chrono::high_resolution_clock::time_point timeout_time( - detail::convert_tp( timeout_time_) ); - return fm_wait_until( timeout_time, lk); -} - -template< typename Rep, typename Period > -bool fm_wait_for( std::chrono::duration< Rep, Period > const& timeout_duration, - std::unique_lock< detail::spinlock > & lk) { - return wait_until( std::chrono::high_resolution_clock::now() + timeout_duration, lk); -} - -void fm_yield(); - -void fm_join( fiber_context *); - -fiber_context * fm_active() noexcept; - -void fm_set_sched_algo( sched_algorithm *); - -void fm_wait_interval( std::chrono::high_resolution_clock::duration const&) noexcept; - -template< typename Rep, typename Period > -void fm_wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { - fm_wait_interval( wait_interval); -} - -std::chrono::high_resolution_clock::duration fm_wait_interval() noexcept; - -bool fm_preserve_fpu(); - -void fm_preserve_fpu( bool); - }} #ifdef BOOST_HAS_ABI_HEADERS diff --git a/include/boost/fiber/fss.hpp b/include/boost/fiber/fss.hpp index e1ab6978..339e11a2 100644 --- a/include/boost/fiber/fss.hpp +++ b/include/boost/fiber/fss.hpp @@ -62,8 +62,8 @@ public: } ~fiber_specific_ptr() { - if ( fm_active() ) { - fm_active()->set_fss_data( + if ( detail::scheduler::instance()->active() ) { + detail::scheduler::instance()->active()->set_fss_data( this, cleanup_fn_, nullptr, true); } } @@ -72,9 +72,9 @@ public: fiber_specific_ptr & operator=( fiber_specific_ptr const&) = delete; T * get() const { - BOOST_ASSERT( fm_active() ); + BOOST_ASSERT( detail::scheduler::instance()->active() ); - void * vp( fm_active()->get_fss_data( this) ); + void * vp( detail::scheduler::instance()->active()->get_fss_data( this) ); return static_cast< T * >( vp); } @@ -88,7 +88,7 @@ public: T * release() { T * tmp = get(); - fm_active()->set_fss_data( + detail::scheduler::instance()->active()->set_fss_data( this, cleanup_fn_, nullptr, false); return tmp; } @@ -96,7 +96,7 @@ public: void reset( T * t) { T * c = get(); if ( c != t) { - fm_active()->set_fss_data( + detail::scheduler::instance()->active()->set_fss_data( this, cleanup_fn_, t, true); } } diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index f9251e1b..93674b4f 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -26,19 +26,19 @@ namespace this_fiber { inline fibers::fiber::id get_id() noexcept { - return fibers::fm_active()->get_id(); + return fibers::detail::scheduler::instance()->active()->get_id(); } inline void yield() { - fibers::fm_yield(); + fibers::detail::scheduler::instance()->yield(); } template< typename Clock, typename Duration > void sleep_until( std::chrono::time_point< Clock, Duration > const& sleep_time) { fibers::detail::spinlock splk; std::unique_lock< fibers::detail::spinlock > lk( splk); - fibers::fm_wait_until( sleep_time, lk); + fibers::detail::scheduler::instance()->wait_until( sleep_time, lk); // check if fiber was interrupted interruption_point(); @@ -51,12 +51,12 @@ void sleep_for( std::chrono::duration< Rep, Period > const& timeout_duration) { inline bool thread_affinity() noexcept { - return fibers::fm_active()->thread_affinity(); + return fibers::detail::scheduler::instance()->active()->thread_affinity(); } inline void thread_affinity( bool req) noexcept { - fibers::fm_active()->thread_affinity( req); + fibers::detail::scheduler::instance()->active()->thread_affinity( req); } } @@ -65,7 +65,7 @@ namespace fibers { inline void migrate( fiber const& f) { - fm_spawn( detail::scheduler::extract( f) ); + detail::scheduler::instance()->spawn( detail::scheduler::extract( f) ); } inline @@ -75,22 +75,22 @@ void set_scheduling_algorithm( sched_algorithm * al) { template< typename Rep, typename Period > void wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { - fm_wait_interval( wait_interval); + detail::scheduler::instance()->wait_interval( wait_interval); } template< typename Rep, typename Period > std::chrono::duration< Rep, Period > wait_interval() noexcept { - return fm_wait_interval< Rep, Period >(); + return detail::scheduler::instance()->wait_interval< Rep, Period >(); } inline bool preserve_fpu() { - return fm_preserve_fpu(); + return detail::scheduler::instance()->preserve_fpu(); } inline void preserve_fpu( bool preserve) { - return fm_preserve_fpu( preserve); + return detail::scheduler::instance()->preserve_fpu( preserve); } }} diff --git a/src/detail/scheduler.cpp b/src/detail/scheduler.cpp deleted file mode 100644 index d5c5a31a..00000000 --- a/src/detail/scheduler.cpp +++ /dev/null @@ -1,37 +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) - -#include "boost/fiber/detail/scheduler.hpp" - -#include - -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace fibers { -namespace detail { - -fiber_manager * -scheduler::instance() noexcept { - static thread_local fiber_manager mgr; - return & mgr; -} - -void -scheduler::replace( sched_algorithm * other) { - BOOST_ASSERT( nullptr != other); - - fm_set_sched_algo( other); -} - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif diff --git a/src/detail/spinlock.cpp b/src/detail/spinlock.cpp index 05440f1f..0843abcb 100644 --- a/src/detail/spinlock.cpp +++ b/src/detail/spinlock.cpp @@ -8,6 +8,7 @@ #include +#include #include #include @@ -27,7 +28,7 @@ spinlock::lock() { // sucessive acccess to state_ -> cache hit while ( spinlock_status::locked == state_.load( std::memory_order_relaxed) ) { // busy-wait - fm_yield(); + scheduler::instance()->yield(); } // state_ was released by other fiber // cached copies are invalidated -> cache miss diff --git a/src/fiber.cpp b/src/fiber.cpp index f1634af4..e51457cd 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -25,7 +25,7 @@ namespace fibers { void fiber::start_() { impl_->set_ready(); - fm_spawn( impl_.get() ); + detail::scheduler::instance()->spawn( impl_.get() ); } bool @@ -56,7 +56,7 @@ fiber::join() { "boost fiber: fiber not joinable"); } - fm_join( impl_.get() ); + detail::scheduler::instance()->join( impl_.get() ); // check if joined fiber was interrupted std::exception_ptr except( impl_->get_exception() ); diff --git a/src/fiber_manager.cpp b/src/fiber_manager.cpp index c2484ab6..39e91d18 100644 --- a/src/fiber_manager.cpp +++ b/src/fiber_manager.cpp @@ -30,30 +30,28 @@ sched_algorithm * default_algorithm() { } fiber_manager::fiber_manager() noexcept : - sched_algo( default_algorithm() ), - active_fiber( fiber_context::main_fiber() ), - wqueue(), - tqueue(), - preserve_fpu( false), - wait_interval( std::chrono::milliseconds( 10) ) { + sched_algo_( default_algorithm() ), + active_fiber_( fiber_context::main_fiber() ), + wqueue_(), + tqueue_(), + preserve_fpu_( false), + wait_interval_( std::chrono::milliseconds( 10) ) { } fiber_manager::~fiber_manager() noexcept { // fibers will be destroyed (stack-unwinding) // if last reference goes out-of-scope - // therefore destructing fm->wqueue && rqueue_ + // therefore destructing wqueue_ && rqueue_ // will destroy the fibers in this scheduler // if not referenced on other places - while ( ! wqueue.empty() ) { - fm_run(); + while ( ! wqueue_.empty() ) { + run(); } - active_fiber = nullptr; + active_fiber_ = nullptr; } -void fm_resume_( fiber_context * f) { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); +void +fiber_manager::resume_( fiber_context * f) { BOOST_ASSERT( nullptr != f); BOOST_ASSERT( f->is_ready() ); @@ -62,78 +60,70 @@ void fm_resume_( fiber_context * f) { // fiber next-to-run is same as current active fiber // this might happen in context of this_fiber::yield() - if ( f == fm->active_fiber) { + if ( f == active_fiber_) { return; } // assign new fiber to active-fiber - std::swap( fm->active_fiber, f); - // push terminated fibers to tqueue + std::swap( active_fiber_, f); + // push terminated fibers to tqueue_ if ( f->is_terminated() ) { - fm->tqueue.push( f); + tqueue_.push( f); } // resume active-fiber == start or yield to - fm->active_fiber->resume(); + active_fiber_->resume(); } -std::chrono::high_resolution_clock::time_point fm_next_wakeup() { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - if ( fm->wqueue.empty() ) { - return std::chrono::high_resolution_clock::now() + fm->wait_interval; +std::chrono::high_resolution_clock::time_point +fiber_manager::next_wakeup() { + if ( wqueue_.empty() ) { + return std::chrono::high_resolution_clock::now() + wait_interval_; } else { //FIXME: search for the closest time_point to now() in waiting-queue - std::chrono::high_resolution_clock::time_point wakeup( fm->wqueue.top()->time_point() ); + std::chrono::high_resolution_clock::time_point wakeup( wqueue_.top()->time_point() ); if ( (std::chrono::high_resolution_clock::time_point::max)() == wakeup) { - return std::chrono::high_resolution_clock::now() + fm->wait_interval; + return std::chrono::high_resolution_clock::now() + wait_interval_; } return wakeup; } } -void fm_spawn( fiber_context * f) { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); +void +fiber_manager::spawn( fiber_context * f) { BOOST_ASSERT( nullptr != f); BOOST_ASSERT( f->is_ready() ); - BOOST_ASSERT( f != fm->active_fiber); + BOOST_ASSERT( f != active_fiber_); - fm->sched_algo->awakened( f); + sched_algo_->awakened( f); } -void fm_run() { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - +void +fiber_manager::run() { for (;;) { // move all fibers witch are ready (state_ready) // from waiting-queue to the runnable-queue - fm->wqueue.move_to( fm->sched_algo); + wqueue_.move_to( sched_algo_); // pop new fiber from ready-queue - fiber_context * f( fm->sched_algo->pick_next() ); + fiber_context * f( sched_algo_->pick_next() ); if ( f) { BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); - // destroy terminated fibers from tqueue - while ( ! fm->tqueue.empty() ) { - fiber_context * f_( fm->tqueue.pop() ); + // destroy terminated fibers from tqueue_ + while ( ! tqueue_.empty() ) { + fiber_context * f_( tqueue_.pop() ); BOOST_ASSERT( nullptr != f_); BOOST_ASSERT( f_->is_terminated() ); intrusive_ptr_release( f_); } // resume fiber f - fm_resume_( f); + resume_( f); - // destroy terminated fibers from tqueue - while ( ! fm->tqueue.empty() ) { - fiber_context * f_( fm->tqueue.pop() ); + // destroy terminated fibers from tqueue_ + while ( ! tqueue_.empty() ) { + fiber_context * f_( tqueue_.pop() ); BOOST_ASSERT( nullptr != f_); BOOST_ASSERT( f_->is_terminated() ); intrusive_ptr_release( f_); @@ -143,127 +133,102 @@ void fm_run() { } else { // no fibers ready to run; the thread should sleep // until earliest fiber is scheduled to run - std::chrono::high_resolution_clock::time_point wakeup( fm_next_wakeup() ); + std::chrono::high_resolution_clock::time_point wakeup( next_wakeup() ); std::this_thread::sleep_until( wakeup); } } } -void fm_wait( std::unique_lock< detail::spinlock > & lk) { - fm_wait_until( +void +fiber_manager::wait( std::unique_lock< detail::spinlock > & lk) { + wait_until( std::chrono::high_resolution_clock::time_point( (std::chrono::high_resolution_clock::duration::max)() ), lk); } -bool fm_wait_until( std::chrono::high_resolution_clock::time_point const& timeout_time, +bool +fiber_manager::wait_until( std::chrono::high_resolution_clock::time_point const& timeout_time, std::unique_lock< detail::spinlock > & lk) { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - BOOST_ASSERT( nullptr != fm->active_fiber); - BOOST_ASSERT( fm->active_fiber->is_running() ); + BOOST_ASSERT( active_fiber_->is_running() ); // set active-fiber to state_waiting - fm->active_fiber->set_waiting(); + active_fiber_->set_waiting(); // release lock lk.unlock(); - // push active-fiber to fm->wqueue - fm->active_fiber->time_point( timeout_time); - fm->wqueue.push( fm->active_fiber); + // push active-fiber to wqueue_ + active_fiber_->time_point( timeout_time); + wqueue_.push( active_fiber_); // switch to another fiber - fm_run(); + run(); // fiber is resumed return std::chrono::high_resolution_clock::now() < timeout_time; } -void fm_yield() { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - BOOST_ASSERT( nullptr != fm->active_fiber); - BOOST_ASSERT( fm->active_fiber->is_running() ); +void +fiber_manager::yield() { + BOOST_ASSERT( active_fiber_->is_running() ); // set active-fiber to state_waiting - fm->active_fiber->set_ready(); - // push active-fiber to fm->wqueue - fm->wqueue.push( fm->active_fiber); + active_fiber_->set_ready(); + // push active-fiber to wqueue_ + wqueue_.push( active_fiber_); // switch to another fiber - fm_run(); + run(); // fiber is resumed } -void fm_join( fiber_context * f) { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); +void +fiber_manager::join( fiber_context * f) { BOOST_ASSERT( nullptr != f); - BOOST_ASSERT( f != fm->active_fiber); + BOOST_ASSERT( f != active_fiber_); // set active-fiber to state_waiting - fm->active_fiber->set_waiting(); - // push active-fiber to fm->wqueue - fm->wqueue.push( fm->active_fiber); + active_fiber_->set_waiting(); + // push active-fiber to wqueue_ + wqueue_.push( active_fiber_); // add active-fiber to joinig-list of f - if ( ! f->join( fm->active_fiber) ) { + if ( ! f->join( active_fiber_) ) { // f must be already terminated therefore we set // active-fiber to state_ready // FIXME: better state_running and no suspend - fm->active_fiber->set_ready(); + active_fiber_->set_ready(); } // switch to another fiber - fm_run(); + run(); // fiber is resumed BOOST_ASSERT( f->is_terminated() ); } -fiber_context * fm_active() noexcept { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - return fm->active_fiber; +fiber_context * +fiber_manager::active() noexcept { + return active_fiber_; } -void fm_set_sched_algo( sched_algorithm * algo) { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - fm->sched_algo = algo; +void +fiber_manager::set_sched_algo( sched_algorithm * algo) { + sched_algo_ = algo; } -void fm_wait_interval( std::chrono::high_resolution_clock::duration const& wait_interval) noexcept { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - fm->wait_interval = wait_interval; +void +fiber_manager::wait_interval( std::chrono::high_resolution_clock::duration const& wait_interval) noexcept { + wait_interval_ = wait_interval; } -std::chrono::high_resolution_clock::duration fm_wait_interval() noexcept { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - return fm->wait_interval; +std::chrono::high_resolution_clock::duration +fiber_manager::wait_interval() noexcept { + return wait_interval_; } -bool fm_preserve_fpu() { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - return fm->preserve_fpu; +bool +fiber_manager::preserve_fpu() { + return preserve_fpu_; } -void fm_preserve_fpu( bool preserve) { - fiber_manager * fm = detail::scheduler::instance(); - - BOOST_ASSERT( nullptr != fm); - - fm->preserve_fpu = preserve; +void +fiber_manager::preserve_fpu( bool preserve) { + preserve_fpu_ = preserve; } }} diff --git a/src/interruption.cpp b/src/interruption.cpp index 94c3b7cb..222b62af 100644 --- a/src/interruption.cpp +++ b/src/interruption.cpp @@ -20,42 +20,42 @@ namespace boost { namespace this_fiber { disable_interruption::disable_interruption() noexcept : - set_( ( fibers::fm_active()->interruption_blocked() ) ) { + set_( ( fibers::detail::scheduler::instance()->active()->interruption_blocked() ) ) { if ( ! set_) { - fibers::fm_active()->interruption_blocked( true); + fibers::detail::scheduler::instance()->active()->interruption_blocked( true); } } disable_interruption::~disable_interruption() noexcept { if ( ! set_) { - fibers::fm_active()->interruption_blocked( false); + fibers::detail::scheduler::instance()->active()->interruption_blocked( false); } } restore_interruption::restore_interruption( disable_interruption & disabler) noexcept : disabler_( disabler) { if ( ! disabler_.set_) { - fibers::fm_active()->interruption_blocked( false); + fibers::detail::scheduler::instance()->active()->interruption_blocked( false); } } restore_interruption::~restore_interruption() noexcept { if ( ! disabler_.set_) { - fibers::fm_active()->interruption_blocked( true); + fibers::detail::scheduler::instance()->active()->interruption_blocked( true); } } bool interruption_enabled() noexcept { - return ! fibers::fm_active()->interruption_blocked(); + return ! fibers::detail::scheduler::instance()->active()->interruption_blocked(); } bool interruption_requested() noexcept { - return fibers::fm_active()->interruption_requested(); + return fibers::detail::scheduler::instance()->active()->interruption_requested(); } void interruption_point() { if ( interruption_requested() && interruption_enabled() ) { - fibers::fm_active()->request_interruption( false); + fibers::detail::scheduler::instance()->active()->request_interruption( false); throw fibers::fiber_interrupted(); } } diff --git a/src/mutex.cpp b/src/mutex.cpp index a7506faf..e1d3c0c1 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -48,7 +48,7 @@ mutex::~mutex() { void mutex::lock() { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); BOOST_ASSERT( nullptr != f); for (;;) { std::unique_lock< detail::spinlock > lk( splk_); @@ -62,7 +62,7 @@ mutex::lock() { waiting_.push_back( f); // suspend this fiber - fm_wait( lk); + detail::scheduler::instance()->wait( lk); } } diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp index 13a9b952..679c852b 100644 --- a/src/recursive_mutex.cpp +++ b/src/recursive_mutex.cpp @@ -54,7 +54,7 @@ recursive_mutex::~recursive_mutex() { void recursive_mutex::lock() { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); BOOST_ASSERT( nullptr != f); for (;;) { std::unique_lock< detail::spinlock > lk( splk_); @@ -68,7 +68,7 @@ recursive_mutex::lock() { waiting_.push_back( f); // suspend this fiber - fm_wait( lk); + detail::scheduler::instance()->wait( lk); } } diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp index 98962ac3..3b33c7be 100644 --- a/src/recursive_timed_mutex.cpp +++ b/src/recursive_timed_mutex.cpp @@ -53,7 +53,7 @@ recursive_timed_mutex::~recursive_timed_mutex() { void recursive_timed_mutex::lock() { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); BOOST_ASSERT( nullptr != f); for (;;) { std::unique_lock< detail::spinlock > lk( splk_); @@ -67,7 +67,7 @@ recursive_timed_mutex::lock() { waiting_.push_back( f); // suspend this fiber - fm_wait( lk); + detail::scheduler::instance()->wait( lk); } } @@ -87,7 +87,7 @@ recursive_timed_mutex::try_lock() { bool recursive_timed_mutex::try_lock_until( std::chrono::high_resolution_clock::time_point const& timeout_time) { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); BOOST_ASSERT( nullptr != f); for (;;) { std::unique_lock< detail::spinlock > lk( splk_); @@ -105,7 +105,7 @@ recursive_timed_mutex::try_lock_until( std::chrono::high_resolution_clock::time_ waiting_.push_back( f); // suspend this fiber until notified or timed-out - if ( ! fm_wait_until( timeout_time, lk) ) { + if ( ! detail::scheduler::instance()->wait_until( timeout_time, lk) ) { lk.lock(); std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) { diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp index a989b1bd..fa55248c 100644 --- a/src/timed_mutex.cpp +++ b/src/timed_mutex.cpp @@ -47,7 +47,7 @@ timed_mutex::~timed_mutex() { void timed_mutex::lock() { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); BOOST_ASSERT( nullptr != f); for (;;) { std::unique_lock< detail::spinlock > lk( splk_); @@ -61,7 +61,7 @@ timed_mutex::lock() { waiting_.push_back( f); // suspend this fiber - fm_wait( lk); + detail::scheduler::instance()->wait( lk); } } @@ -81,7 +81,7 @@ timed_mutex::try_lock() { bool timed_mutex::try_lock_until( std::chrono::high_resolution_clock::time_point const& timeout_time) { - fiber_context * f( fm_active() ); + fiber_context * f( detail::scheduler::instance()->active() ); BOOST_ASSERT( nullptr != f); for (;;) { std::unique_lock< detail::spinlock > lk( splk_); @@ -99,7 +99,7 @@ timed_mutex::try_lock_until( std::chrono::high_resolution_clock::time_point cons waiting_.push_back( f); // suspend this fiber until notified or timed-out - if ( ! fm_wait_until( timeout_time, lk) ) { + if ( ! detail::scheduler::instance()->wait_until( timeout_time, lk) ) { lk.lock(); std::deque< fiber_context * >::iterator i( std::find( waiting_.begin(), waiting_.end(), f) ); if ( waiting_.end() != i) {