From cfdcf1d16a98a9cb72b36f813faacc91eac9b8e6 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 19 Dec 2012 19:37:05 +0100 Subject: [PATCH] interface algorithm, round_robin --- build/Jamfile.v2 | 4 +- examples/barrier.cpp | 2 +- examples/future.cpp | 2 +- examples/join.cpp | 2 +- examples/ping_pong.cpp | 2 +- examples/simple.cpp | 2 +- include/boost/fiber/algorithm.hpp | 64 ++++++ include/boost/fiber/all.hpp | 5 +- include/boost/fiber/condition.hpp | 18 +- .../boost/fiber/{ => detail}/scheduler.hpp | 54 ++--- include/boost/fiber/fiber.hpp | 20 +- include/boost/fiber/future.hpp | 6 +- include/boost/fiber/interruption.hpp | 2 +- include/boost/fiber/operations.hpp | 20 +- ...{default_scheduler.hpp => round_robin.hpp} | 24 +- src/auto_reset_event.cpp | 36 +-- src/condition.cpp | 6 +- src/count_down_event.cpp | 16 +- src/detail/fiber_base.cpp | 4 +- src/{ => detail}/scheduler.cpp | 18 +- src/fiber.cpp | 8 +- src/manual_reset_event.cpp | 80 +++---- src/mutex.cpp | 16 +- ...{default_scheduler.cpp => round_robin.cpp} | 25 +-- test/test_auto_reset_event.cpp | 12 +- test/test_barrier.cpp | 4 +- test/test_condition.cpp | 16 +- test/test_count_down_event.cpp | 8 +- test/test_fiber.cpp | 48 ++-- test/test_futures.cpp | 212 +++++++++--------- test/test_generic_locks.cpp | 40 ++-- test/test_lock.cpp | 44 ++-- test/test_manual_reset_event.cpp | 8 +- test/test_mutex.cpp | 8 +- test/test_unique_lock.cpp | 44 ++-- test/test_waitfor.cpp | 12 +- 36 files changed, 473 insertions(+), 419 deletions(-) create mode 100644 include/boost/fiber/algorithm.hpp rename include/boost/fiber/{ => detail}/scheduler.hpp (64%) rename include/boost/fiber/{default_scheduler.hpp => round_robin.hpp} (84%) rename src/{ => detail}/scheduler.cpp (73%) rename src/{default_scheduler.cpp => round_robin.cpp} (89%) diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 1d8aab48..1140e359 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -25,12 +25,12 @@ lib boost_fibers barrier.cpp condition.cpp count_down_event.cpp - default_scheduler.cpp detail/fiber_base.cpp + detail/scheduler.cpp fiber.cpp manual_reset_event.cpp mutex.cpp - scheduler.cpp + round_robin.cpp : shared:BOOST_FIBERS_DYN_LINK=1 : : shared:../../context/build//boost_context diff --git a/examples/barrier.cpp b/examples/barrier.cpp index d3c01bb7..9bad3067 100644 --- a/examples/barrier.cpp +++ b/examples/barrier.cpp @@ -73,7 +73,7 @@ void fn2( stm::barrier & b) int main() { - stm::default_scheduler ds; + stm::round_robin ds; stm::scheduler::replace( & ds); try { diff --git a/examples/future.cpp b/examples/future.cpp index 86596fe9..c256a6a5 100644 --- a/examples/future.cpp +++ b/examples/future.cpp @@ -33,7 +33,7 @@ void start() int main() { - stm::default_scheduler ds; + stm::round_robin ds; stm::scheduler::replace( & ds); try { diff --git a/examples/join.cpp b/examples/join.cpp index dbffe708..6aaadd2c 100644 --- a/examples/join.cpp +++ b/examples/join.cpp @@ -44,7 +44,7 @@ void fn2( stm::fiber & s) int main() { - stm::default_scheduler ds; + stm::round_robin ds; stm::scheduler::replace( & ds); try { diff --git a/examples/ping_pong.cpp b/examples/ping_pong.cpp index e28b8d07..dc3b5cac 100644 --- a/examples/ping_pong.cpp +++ b/examples/ping_pong.cpp @@ -83,7 +83,7 @@ void f() int main() { - stm::default_scheduler ds; + stm::round_robin ds; stm::scheduler::replace( & ds); try { diff --git a/examples/simple.cpp b/examples/simple.cpp index 8c419068..69b10374 100644 --- a/examples/simple.cpp +++ b/examples/simple.cpp @@ -21,7 +21,7 @@ void fn( std::string const& str, int n) int main() { - stm::default_scheduler ds; + stm::round_robin ds; stm::scheduler::replace( & ds); try { diff --git a/include/boost/fiber/algorithm.hpp b/include/boost/fiber/algorithm.hpp new file mode 100644 index 00000000..d6bbfaed --- /dev/null +++ b/include/boost/fiber/algorithm.hpp @@ -0,0 +1,64 @@ +// Copyright Oliver Kowalke 2009. +// 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) + +#ifndef BOOST_FIBERS_ALGORITHM_H +#define BOOST_FIBERS_ALGORITHM_H + +#include +#include +#include +#include + +#include +#include + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +# if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4251 4275) +# endif + +namespace boost { +namespace fibers { + +struct BOOST_FIBERS_DECL algorithm : private noncopyable +{ + virtual void spawn( detail::fiber_base::ptr_t const&) = 0; + + virtual void join( detail::fiber_base::ptr_t const&) = 0; + + virtual void cancel( detail::fiber_base::ptr_t const&) = 0; + + virtual void notify( detail::fiber_base::ptr_t const&) = 0; + + virtual detail::fiber_base::ptr_t active() = 0; + + virtual void sleep( chrono::system_clock::time_point const& abs_time) = 0; + + virtual bool run() = 0; + + virtual void wait() = 0; + + virtual void yield() = 0; + + virtual void migrate( detail::fiber_base::ptr_t const&) = 0; + + virtual ~algorithm() {} +}; + +}} + +# if defined(BOOST_MSVC) +# pragma warning(pop) +# endif + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + +#endif // BOOST_FIBERS_ALGORITHM_H diff --git a/include/boost/fiber/all.hpp b/include/boost/fiber/all.hpp index 8783dcdb..eb19dc78 100644 --- a/include/boost/fiber/all.hpp +++ b/include/boost/fiber/all.hpp @@ -7,19 +7,20 @@ #ifndef BOOST_FIBERS_H #define BOOST_FIBERS_H +#include #include #include #include #include #include -#include #include #include #include #include #include #include -#include +#include +#include #include #endif // BOOST_FIBERS_H diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index 69ada792..514c417c 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -89,11 +89,11 @@ public: if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().wait(); + detail::scheduler::instance().active() ); + detail::scheduler::instance().wait(); } else - scheduler::instance().run(); + detail::scheduler::instance().run(); } if ( NOTIFY_ONE == cmd_) @@ -161,24 +161,24 @@ public: if ( now >= abs_time) { while ( ! ( timed_out = enter_mtx_.try_lock() ) ) - scheduler::instance().yield(); + detail::scheduler::instance().yield(); break; } if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().sleep( abs_time); + detail::scheduler::instance().active() ); + detail::scheduler::instance().sleep( abs_time); } else - scheduler::instance().run(); + detail::scheduler::instance().run(); now = chrono::system_clock::now(); if ( now >= abs_time) { while ( ! ( timed_out = enter_mtx_.try_lock() ) ) - scheduler::instance().yield(); + detail::scheduler::instance().yield(); break; } } diff --git a/include/boost/fiber/scheduler.hpp b/include/boost/fiber/detail/scheduler.hpp similarity index 64% rename from include/boost/fiber/scheduler.hpp rename to include/boost/fiber/detail/scheduler.hpp index bb5fd762..5c7e76fa 100644 --- a/include/boost/fiber/scheduler.hpp +++ b/include/boost/fiber/detail/scheduler.hpp @@ -3,8 +3,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_FIBERS_SCHEDULER_H -#define BOOST_FIBERS_SCHEDULER_H +#ifndef BOOST_FIBERS_DETAIL_SCHEDULER_H +#define BOOST_FIBERS_DETAIL_SCHEDULER_H #if defined(__APPLE__) && defined(BOOST_HAS_PTHREADS) #include // pthread_key_create, pthread_[gs]etspecific @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -29,14 +30,11 @@ namespace boost { namespace fibers { +namespace detail { // thread_local_ptr was a contribution from // Nat Goodspeed #if defined(__APPLE__) && defined(BOOST_HAS_PTHREADS) -class scheduler; - -namespace detail { - class thread_local_ptr : private noncopyable { private: @@ -51,22 +49,22 @@ public: thread_local_ptr() BOOST_NOEXCEPT { BOOST_ASSERT( ! ::pthread_key_create( & key_, 0) ); } - scheduler * get() const BOOST_NOEXCEPT - { return static_cast< scheduler * >( ::pthread_getspecific( key_) ); } + algorithm * get() const BOOST_NOEXCEPT + { return static_cast< algorithm * >( ::pthread_getspecific( key_) ); } - thread_local_ptr & operator=( scheduler * ptr) BOOST_NOEXCEPT + thread_local_ptr & operator=( algorithm * ptr) BOOST_NOEXCEPT { ::pthread_setspecific( key_, ptr); return * this; } - scheduler & operator*() const BOOST_NOEXCEPT + algorithm & operator*() const BOOST_NOEXCEPT { return * get(); } - scheduler * operator->() const BOOST_NOEXCEPT + algorithm * operator->() const BOOST_NOEXCEPT { return get(); } - operator scheduler * () const BOOST_NOEXCEPT + operator algorithm * () const BOOST_NOEXCEPT { return get(); } operator safe_bool() const BOOST_NOEXCEPT @@ -90,40 +88,20 @@ class BOOST_FIBERS_DECL scheduler : private noncopyable private: #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) || \ (defined(__ICC) && defined(BOOST_WINDOWS)) - static __declspec(thread) scheduler * instance_; + static __declspec(thread) algorithm * instance_; #elif defined(BOOST_MAC_PTHREADS) static detail::thread_local_ptr instance_; #else - static __thread scheduler * instance_; + static __thread algorithm * instance_; #endif public: - static scheduler & instance(); + static algorithm & instance(); - static scheduler * replace( scheduler *) BOOST_NOEXCEPT; - - virtual void spawn( detail::fiber_base::ptr_t const&) = 0; - - virtual void join( detail::fiber_base::ptr_t const&) = 0; - - virtual void cancel( detail::fiber_base::ptr_t const&) = 0; - - virtual void notify( detail::fiber_base::ptr_t const&) = 0; - - virtual detail::fiber_base::ptr_t active() = 0; - - virtual void sleep( chrono::system_clock::time_point const& abs_time) = 0; - - virtual bool run() = 0; - - virtual void wait() = 0; - - virtual void yield() = 0; - - virtual ~scheduler() {} + static algorithm * replace( algorithm *) BOOST_NOEXCEPT; }; -}} +}}} # if defined(BOOST_MSVC) # pragma warning(pop) @@ -133,4 +111,4 @@ public: # include BOOST_ABI_SUFFIX #endif -#endif // BOOST_FIBERS_SCHEDULER_H +#endif // BOOST_FIBERS_DETAIL_SCHEDULER_H diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index f5c0d636..17976ba7 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -34,21 +34,11 @@ namespace boost { namespace fibers { -namespace detail { - -class scheduler; - -} - -class fiber; -fiber migrate_from(); -void migrate_to( BOOST_RV_REF( fiber) ); class BOOST_FIBERS_DECL fiber { private: - friend fiber migrate_from(); - friend void migrate_to( BOOST_RV_REF( fiber) ); + friend void migrate( fiber &); struct dummy { void nonnull() {} }; @@ -63,10 +53,6 @@ private: BOOST_MOVABLE_BUT_NOT_COPYABLE( fiber); - fiber( ptr_t const& impl) BOOST_NOEXCEPT : - impl_( impl) - { BOOST_ASSERT( impl_); } - public: typedef detail::fiber_base::id id; @@ -74,6 +60,10 @@ public: impl_() {} + fiber( ptr_t const& impl) BOOST_NOEXCEPT : + impl_( impl) + { BOOST_ASSERT( impl_); } + #ifndef BOOST_NO_RVALUE_REFERENCES #ifdef BOOST_MSVC typedef void ( * fiber_fn)(); diff --git a/include/boost/fiber/future.hpp b/include/boost/fiber/future.hpp index ba8c8861..2e4b030b 100644 --- a/include/boost/fiber/future.hpp +++ b/include/boost/fiber/future.hpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include namespace boost { @@ -171,12 +171,12 @@ namespace fibers { do_callback(lock); while(!done) { - if ( boost::fibers::scheduler::instance().active() ) + if ( boost::fibers::detail::scheduler::instance().active() ) waiters.wait(lock); else { lock.unlock(); - boost::fibers::scheduler::instance().run(); + boost::fibers::detail::scheduler::instance().run(); lock.lock(); } } diff --git a/include/boost/fiber/interruption.hpp b/include/boost/fiber/interruption.hpp index c02186cd..698b7c58 100644 --- a/include/boost/fiber/interruption.hpp +++ b/include/boost/fiber/interruption.hpp @@ -14,7 +14,7 @@ #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 417f591f..3bfb1da4 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -15,8 +15,8 @@ #include #include -#include #include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -28,20 +28,20 @@ namespace this_fiber { inline bool is_fiberized() -{ return fibers::scheduler::instance().active(); } +{ return fibers::detail::scheduler::instance().active(); } inline fibers::fiber::id get_id() { BOOST_ASSERT( is_fiberized() ); - return fibers::scheduler::instance().active()->get_id(); + return fibers::detail::scheduler::instance().active()->get_id(); } inline void sleep( chrono::system_clock::time_point const& abs_time) { BOOST_ASSERT( is_fiberized() ); - fibers::scheduler::instance().sleep( abs_time); + fibers::detail::scheduler::instance().sleep( abs_time); } template< typename TimeDuration > @@ -52,7 +52,7 @@ inline void yield() { BOOST_ASSERT( is_fiberized() ); - fibers::scheduler::instance().yield(); + fibers::detail::scheduler::instance().yield(); } inline @@ -68,7 +68,15 @@ namespace fibers { inline bool run() -{ return scheduler::instance().run(); } +{ return detail::scheduler::instance().run(); } + +inline +algorithm * scheduling_algorithm( algorithm * al) +{ return detail::scheduler::replace( al); } + +inline +void migrate( fiber & f) +{ detail::scheduler::instance().migrate( f.impl_); } #if 0 #define BOOST_FIBERS_WAITFOR_FIBER_FN_ARG(z,n,unused) \ diff --git a/include/boost/fiber/default_scheduler.hpp b/include/boost/fiber/round_robin.hpp similarity index 84% rename from include/boost/fiber/default_scheduler.hpp rename to include/boost/fiber/round_robin.hpp index 13680c60..934465aa 100644 --- a/include/boost/fiber/default_scheduler.hpp +++ b/include/boost/fiber/round_robin.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -31,7 +31,7 @@ namespace boost { namespace fibers { -class BOOST_FIBERS_DECL default_scheduler : public scheduler +class BOOST_FIBERS_DECL round_robin : public algorithm { private: struct schedulable @@ -80,7 +80,22 @@ private: tp_idx_t & tp_idx_; public: - default_scheduler(); + typedef rqueue_t::iterator iterator; + typedef rqueue_t::const_iterator const_iterator; + + round_robin() BOOST_NOEXCEPT; + + iterator begin() + { return rqueue_.begin(); } + + const_iterator begin() const + { return rqueue_.begin(); } + + iterator end() + { return rqueue_.end(); } + + const_iterator end() const + { return rqueue_.end(); } void spawn( detail::fiber_base::ptr_t const&); @@ -101,7 +116,8 @@ public: void yield(); - ~default_scheduler(); + void migrate( detail::fiber_base::ptr_t const& f) + { rqueue_.push_back( f); } }; }} diff --git a/src/auto_reset_event.cpp b/src/auto_reset_event.cpp index 565cf66c..beb540c8 100644 --- a/src/auto_reset_event.cpp +++ b/src/auto_reset_event.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -22,41 +22,41 @@ namespace boost { namespace fibers { auto_reset_event::auto_reset_event( bool isset) : - state_( isset ? SET : RESET), + state_( isset ? SET : RESET), waiting_() {} void auto_reset_event::wait() { - while ( SET != state_) - { - if ( this_fiber::is_fiberized() ) + while ( SET != state_) + { + if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().wait(); + detail::scheduler::instance().active() ); + detail::scheduler::instance().wait(); } else - scheduler::instance().run(); - } + detail::scheduler::instance().run(); + } state_ = RESET; } bool auto_reset_event::timed_wait( chrono::system_clock::time_point const& abs_time) { - while ( SET != state_) - { - if ( this_fiber::is_fiberized() ) + while ( SET != state_) + { + if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().sleep( abs_time); + detail::scheduler::instance().active() ); + detail::scheduler::instance().sleep( abs_time); } else - scheduler::instance().run(); - } + detail::scheduler::instance().run(); + } state_ = RESET; return chrono::system_clock::now() <= abs_time; } @@ -75,7 +75,7 @@ auto_reset_event::try_wait() void auto_reset_event::set() { - if ( ! waiting_.empty() ) + if ( ! waiting_.empty() ) { detail::fiber_base::ptr_t f; do @@ -84,7 +84,7 @@ auto_reset_event::set() waiting_.pop_front(); } while ( f->is_complete() ); if ( f) - scheduler::instance().notify( f); + detail::scheduler::instance().notify( f); } state_ = SET; } diff --git a/src/condition.cpp b/src/condition.cpp index 32eb6d55..35d74204 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -10,7 +10,7 @@ #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -50,7 +50,7 @@ condition::notify_one() waiting_.pop_front(); } while ( f->is_complete() ); if ( f) - scheduler::instance().notify( f); + detail::scheduler::instance().notify( f); } cmd_ = NOTIFY_ONE; } @@ -71,7 +71,7 @@ condition::notify_all() BOOST_FOREACH( detail::fiber_base::ptr_t const& f, waiting_) { if ( ! f->is_complete() ) - scheduler::instance().notify( f); + detail::scheduler::instance().notify( f); } waiting_.clear(); } diff --git a/src/count_down_event.cpp b/src/count_down_event.cpp index d6c3068c..5051b312 100644 --- a/src/count_down_event.cpp +++ b/src/count_down_event.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -48,7 +48,7 @@ count_down_event::set() BOOST_FOREACH( detail::fiber_base::ptr_t const& f, waiting_) { if ( ! f->is_complete() ) - scheduler::instance().notify( f); + detail::scheduler::instance().notify( f); } waiting_.clear(); } @@ -62,11 +62,11 @@ count_down_event::wait() if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().wait(); + detail::scheduler::instance().active() ); + detail::scheduler::instance().wait(); } else - scheduler::instance().run(); + detail::scheduler::instance().run(); } } @@ -78,11 +78,11 @@ count_down_event::timed_wait( chrono::system_clock::time_point const& abs_time) if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().sleep( abs_time); + detail::scheduler::instance().active() ); + detail::scheduler::instance().sleep( abs_time); } else - scheduler::instance().run(); + detail::scheduler::instance().run(); } return chrono::system_clock::now() <= abs_time; } diff --git a/src/detail/fiber_base.cpp b/src/detail/fiber_base.cpp index d2d72edb..e6aad409 100644 --- a/src/detail/fiber_base.cpp +++ b/src/detail/fiber_base.cpp @@ -10,7 +10,7 @@ #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -27,7 +27,7 @@ fiber_base::notify_() BOOST_ASSERT( ! is_resumed() ); BOOST_FOREACH( fiber_base::ptr_t & p, joining_) - { boost::fibers::scheduler::instance().notify( p); } + { boost::fibers::detail::scheduler::instance().notify( p); } joining_.clear(); } diff --git a/src/scheduler.cpp b/src/detail/scheduler.cpp similarity index 73% rename from src/scheduler.cpp rename to src/detail/scheduler.cpp index ec1d214e..fa7d5cad 100644 --- a/src/scheduler.cpp +++ b/src/detail/scheduler.cpp @@ -5,10 +5,9 @@ #define BOOST_FIBERS_SOURCE -#include +#include #include -#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -16,32 +15,33 @@ namespace boost { namespace fibers { +namespace detail { #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) || \ (defined(__ICC) && defined(BOOST_WINDOWS)) -__declspec(thread) scheduler * scheduler::instance_ = 0; +__declspec(thread) algorithm * scheduler::instance_ = 0; #elif defined(BOOST_MAC_PTHREADS) detail::thread_local_ptr scheduler::instance_ = 0; #else -__thread scheduler * scheduler::instance_ = 0; +__thread algorithm * scheduler::instance_ = 0; #endif -scheduler & +algorithm & scheduler::instance() { BOOST_ASSERT( instance_); return * instance_; } -scheduler * -scheduler::replace( scheduler * other) +algorithm * +scheduler::replace( algorithm * other) { - scheduler * old = instance_; + algorithm * old = instance_; instance_ = other; return old; } -}} +}}} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/src/fiber.cpp b/src/fiber.cpp index 43cac97c..f35835d9 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -22,13 +22,13 @@ namespace fibers { void fiber::spawn_( ptr_t & f) -{ scheduler::instance().spawn( f); } +{ detail::scheduler::instance().spawn( f); } void fiber::cancel() { BOOST_ASSERT( impl_); - scheduler::instance().cancel( impl_); + detail::scheduler::instance().cancel( impl_); } bool @@ -36,7 +36,7 @@ fiber::join() { BOOST_ASSERT( impl_); if ( ! impl_->is_complete() ) - scheduler::instance().join( impl_); + detail::scheduler::instance().join( impl_); BOOST_ASSERT( impl_->is_complete() ); return ! impl_->is_canceled(); } diff --git a/src/manual_reset_event.cpp b/src/manual_reset_event.cpp index 1d3860d7..983bd8a2 100644 --- a/src/manual_reset_event.cpp +++ b/src/manual_reset_event.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -22,78 +22,78 @@ namespace boost { namespace fibers { manual_reset_event::manual_reset_event( bool isset) : - state_( isset ? SET : RESET), - waiters_( 0), - enter_mtx_( false), + state_( isset ? SET : RESET), + waiters_( 0), + enter_mtx_( false), waiting_() {} void manual_reset_event::wait() { - { - mutex::scoped_lock lk( enter_mtx_); + { + mutex::scoped_lock lk( enter_mtx_); BOOST_ASSERT( lk); - ++waiters_; - } + ++waiters_; + } - while ( RESET == state_) - { - if ( this_fiber::is_fiberized() ) + while ( RESET == state_) + { + if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().wait(); + detail::scheduler::instance().active() ); + detail::scheduler::instance().wait(); } else - scheduler::instance().run(); - } + detail::scheduler::instance().run(); + } - if ( 0 == --waiters_) - enter_mtx_.unlock(); + if ( 0 == --waiters_) + enter_mtx_.unlock(); } bool manual_reset_event::timed_wait( chrono::system_clock::time_point const& abs_time) { - { - mutex::scoped_lock lk( enter_mtx_); + { + mutex::scoped_lock lk( enter_mtx_); BOOST_ASSERT( lk); - ++waiters_; - } + ++waiters_; + } - while ( RESET == state_) - { - if ( this_fiber::is_fiberized() ) + while ( RESET == state_) + { + if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().sleep( abs_time); + detail::scheduler::instance().active() ); + detail::scheduler::instance().sleep( abs_time); } else - scheduler::instance().run(); - } + detail::scheduler::instance().run(); + } - if ( 0 == --waiters_) - enter_mtx_.unlock(); + if ( 0 == --waiters_) + enter_mtx_.unlock(); return chrono::system_clock::now() <= abs_time; } bool manual_reset_event::try_wait() { - { - mutex::scoped_lock lk( enter_mtx_); - BOOST_ASSERT( lk); - ++waiters_; - } + { + mutex::scoped_lock lk( enter_mtx_); + BOOST_ASSERT( lk); + ++waiters_; + } - bool result = SET == state_; + bool result = SET == state_; - if ( 0 == --waiters_) - enter_mtx_.unlock(); + if ( 0 == --waiters_) + enter_mtx_.unlock(); - return result; + return result; } void @@ -108,7 +108,7 @@ manual_reset_event::set() BOOST_FOREACH ( detail::fiber_base::ptr_t const& f, waiting_) { if ( ! f->is_complete() ) - scheduler::instance().notify( f); + detail::scheduler::instance().notify( f); } waiting_.clear(); } diff --git a/src/mutex.cpp b/src/mutex.cpp index be4fd36f..8ebda073 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -35,15 +35,15 @@ mutex::lock() if ( this_fiber::is_fiberized() ) { waiting_.push_back( - scheduler::instance().active() ); - scheduler::instance().wait(); + detail::scheduler::instance().active() ); + detail::scheduler::instance().wait(); } else - scheduler::instance().run(); + detail::scheduler::instance().run(); } state_ = LOCKED; if ( this_fiber::is_fiberized() ) - owner_ = scheduler::instance().active()->get_id(); + owner_ = detail::scheduler::instance().active()->get_id(); else owner_ = detail::fiber_base::id(); } @@ -54,7 +54,7 @@ mutex::try_lock() if ( LOCKED == state_) return false; state_ = LOCKED; if ( this_fiber::is_fiberized() ) - owner_ = scheduler::instance().active()->get_id(); + owner_ = detail::scheduler::instance().active()->get_id(); else owner_ = detail::fiber_base::id(); return true; @@ -67,7 +67,7 @@ mutex::unlock() { if ( this_fiber::is_fiberized() ) { - if ( scheduler::instance().active()->get_id() != owner_) + if ( detail::scheduler::instance().active()->get_id() != owner_) std::abort(); } else if ( detail::fiber_base::id() != owner_) @@ -83,7 +83,7 @@ mutex::unlock() waiting_.pop_front(); } while ( f->is_complete() ); if ( f) - scheduler::instance().notify( f); + detail::scheduler::instance().notify( f); } state_ = UNLOCKED; owner_ = detail::fiber_base::id(); diff --git a/src/default_scheduler.cpp b/src/round_robin.cpp similarity index 89% rename from src/default_scheduler.cpp rename to src/round_robin.cpp index fa95a5c5..9c9ab1d6 100644 --- a/src/default_scheduler.cpp +++ b/src/round_robin.cpp @@ -5,7 +5,7 @@ #define BOOST_FIBERS_SOURCE -#include +#include #include #include @@ -31,7 +31,7 @@ namespace boost { namespace fibers { -default_scheduler::default_scheduler() : +round_robin::round_robin() : active_fiber_(), rqueue_(), wqueue_(), @@ -39,11 +39,8 @@ default_scheduler::default_scheduler() : tp_idx_( wqueue_.get< tp_tag_t >() ) {} -default_scheduler::~default_scheduler() -{} - void -default_scheduler::spawn( detail::fiber_base::ptr_t const& f) +round_robin::spawn( detail::fiber_base::ptr_t const& f) { BOOST_ASSERT( f); BOOST_ASSERT( ! f->is_complete() ); @@ -58,7 +55,7 @@ default_scheduler::spawn( detail::fiber_base::ptr_t const& f) } void -default_scheduler::join( detail::fiber_base::ptr_t const& f) +round_robin::join( detail::fiber_base::ptr_t const& f) { BOOST_ASSERT( f); BOOST_ASSERT( ! f->is_complete() ); @@ -67,7 +64,7 @@ default_scheduler::join( detail::fiber_base::ptr_t const& f) if ( active_fiber_) { // store active-fiber as waiting fiber in p - // detail::fiber_base::join() calls default_scheduler::wait() + // detail::fiber_base::join() calls round_robin::wait() // so that active-fiber gets suspended f->join( active_fiber_); // suspend active-fiber until f becomes complete @@ -84,7 +81,7 @@ default_scheduler::join( detail::fiber_base::ptr_t const& f) } void -default_scheduler::cancel( detail::fiber_base::ptr_t const& f) +round_robin::cancel( detail::fiber_base::ptr_t const& f) { BOOST_ASSERT( f); BOOST_ASSERT( f != active_fiber_); @@ -110,7 +107,7 @@ default_scheduler::cancel( detail::fiber_base::ptr_t const& f) } void -default_scheduler::notify( detail::fiber_base::ptr_t const& f) +round_robin::notify( detail::fiber_base::ptr_t const& f) { BOOST_ASSERT( f); BOOST_ASSERT( ! f->is_complete() ); @@ -128,7 +125,7 @@ default_scheduler::notify( detail::fiber_base::ptr_t const& f) } bool -default_scheduler::run() +round_robin::run() { // get all fibers with reached dead-line and push them // at the front of runnable-queue @@ -162,7 +159,7 @@ default_scheduler::run() } void -default_scheduler::wait() +round_robin::wait() { BOOST_ASSERT( active_fiber_); BOOST_ASSERT( ! active_fiber_->is_complete() ); @@ -179,7 +176,7 @@ default_scheduler::wait() } void -default_scheduler::yield() +round_robin::yield() { BOOST_ASSERT( active_fiber_); BOOST_ASSERT( ! active_fiber_->is_complete() ); @@ -195,7 +192,7 @@ default_scheduler::yield() } void -default_scheduler::sleep( chrono::system_clock::time_point const& abs_time) +round_robin::sleep( chrono::system_clock::time_point const& abs_time) { BOOST_ASSERT( active_fiber_); BOOST_ASSERT( ! active_fiber_->is_complete() ); diff --git a/test/test_auto_reset_event.cpp b/test/test_auto_reset_event.cpp index c74c6341..32ef02fd 100644 --- a/test/test_auto_reset_event.cpp +++ b/test/test_auto_reset_event.cpp @@ -115,8 +115,8 @@ void fn3() void test_wait_set() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn1).join(); fn1(); @@ -124,8 +124,8 @@ void test_wait_set() void test_wait_reset() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn2).join(); fn2(); @@ -133,8 +133,8 @@ void test_wait_reset() void test_try_wait() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn3).join(); fn3(); diff --git a/test/test_barrier.cpp b/test/test_barrier.cpp index 3a95aaf8..5133a4ac 100644 --- a/test/test_barrier.cpp +++ b/test/test_barrier.cpp @@ -52,8 +52,8 @@ void fn2( stm::barrier & b) void test_barrier() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); value1 = 0; value2 = 0; diff --git a/test/test_condition.cpp b/test/test_condition.cpp index 58d84843..9b5885d6 100644 --- a/test/test_condition.cpp +++ b/test/test_condition.cpp @@ -198,8 +198,8 @@ void do_test_condition_waits() void test_one_waiter_notify_one() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); value = 0; stm::mutex mtx; @@ -233,8 +233,8 @@ void test_one_waiter_notify_one() void test_two_waiter_notify_one() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); value = 0; stm::mutex mtx; @@ -290,8 +290,8 @@ void test_two_waiter_notify_one() void test_two_waiter_notify_all() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); value = 0; stm::mutex mtx; @@ -363,8 +363,8 @@ void test_two_waiter_notify_all() void test_condition_waits() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); do_test_condition_waits(); } diff --git a/test/test_count_down_event.cpp b/test/test_count_down_event.cpp index 50732b71..1a59499a 100644 --- a/test/test_count_down_event.cpp +++ b/test/test_count_down_event.cpp @@ -88,8 +88,8 @@ void fn2() void test_count_down() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn1).join(); fn1(); @@ -97,8 +97,8 @@ void test_count_down() void test_wait() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn2).join(); fn2(); diff --git a/test/test_fiber.cpp b/test/test_fiber.cpp index 2da52dee..b3a75e29 100644 --- a/test/test_fiber.cpp +++ b/test/test_fiber.cpp @@ -125,8 +125,8 @@ void f8( int t, stm::fiber & s, int & i) void test_move() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); { stm::fiber s1; @@ -151,8 +151,8 @@ void test_move() void test_id() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber s1; stm::fiber s2( f1); @@ -175,8 +175,8 @@ void test_id() void test_detach() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber s1( f1); BOOST_CHECK( ! s1); @@ -191,11 +191,11 @@ void test_detach() void test_replace() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); - stm::scheduler::replace( - new stm::default_scheduler() ); + stm::scheduling_algorithm( + new stm::round_robin() ); stm::fiber s1( f1); BOOST_CHECK( ! s1); stm::fiber s2( f2); @@ -204,8 +204,8 @@ void test_replace() void test_complete() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber s1( f1); BOOST_CHECK( ! s1); @@ -215,8 +215,8 @@ void test_complete() void test_cancel() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); { stm::fiber s( f2); @@ -239,8 +239,8 @@ void test_cancel() void test_join() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); { stm::fiber s( f2); @@ -278,8 +278,8 @@ void test_join() void test_yield_break() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber s( f5); BOOST_CHECK( ! s); @@ -288,8 +288,8 @@ void test_yield_break() void test_yield() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); int v1 = 0, v2 = 0; BOOST_CHECK_EQUAL( 0, v1); @@ -305,8 +305,8 @@ void test_yield() void test_sleep() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); int v1 = 0, v2 = 0; BOOST_CHECK_EQUAL( 0, v1); @@ -326,8 +326,8 @@ void test_sleep() void test_sleep_and_cancel() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); { int v1 = 0, v2 = 0; diff --git a/test/test_futures.cpp b/test/test_futures.cpp index 5bd05a9c..b17b641c 100644 --- a/test/test_futures.cpp +++ b/test/test_futures.cpp @@ -1156,8 +1156,8 @@ void wait_for_all_five_futures() void test_store_value_from_thread() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( store_value_from_thread).join(); store_value_from_thread(); @@ -1165,8 +1165,8 @@ void test_store_value_from_thread() void test_store_exception() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( store_exception).join(); store_exception(); @@ -1174,8 +1174,8 @@ void test_store_exception() void test_initial_state() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( initial_state).join(); initial_state(); @@ -1183,8 +1183,8 @@ void test_initial_state() void test_waiting_future() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( waiting_future).join(); waiting_future(); @@ -1192,8 +1192,8 @@ void test_waiting_future() void test_cannot_get_future_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( cannot_get_future_twice).join(); cannot_get_future_twice(); @@ -1201,8 +1201,8 @@ void test_cannot_get_future_twice() void test_set_value_updates_future_state() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( set_value_updates_future_state).join(); set_value_updates_future_state(); @@ -1210,8 +1210,8 @@ void test_set_value_updates_future_state() void test_set_value_can_be_retrieved() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( set_value_can_be_retrieved).join(); set_value_can_be_retrieved(); @@ -1223,8 +1223,8 @@ void test_set_value_can_be_moved() void test_future_from_packaged_task_is_waiting() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( future_from_packaged_task_is_waiting).join(); future_from_packaged_task_is_waiting(); @@ -1232,8 +1232,8 @@ void test_future_from_packaged_task_is_waiting() void test_invoking_a_packaged_task_populates_future() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( invoking_a_packaged_task_populates_future).join(); invoking_a_packaged_task_populates_future(); @@ -1241,8 +1241,8 @@ void test_invoking_a_packaged_task_populates_future() void test_invoking_a_packaged_task_twice_throws() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( invoking_a_packaged_task_twice_throws).join(); invoking_a_packaged_task_twice_throws(); @@ -1250,8 +1250,8 @@ void test_invoking_a_packaged_task_twice_throws() void test_cannot_get_future_twice_from_task() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( cannot_get_future_twice_from_task).join(); cannot_get_future_twice_from_task(); @@ -1259,8 +1259,8 @@ void test_cannot_get_future_twice_from_task() void test_task_stores_exception_if_function_throws() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( task_stores_exception_if_function_throws).join(); task_stores_exception_if_function_throws(); @@ -1268,8 +1268,8 @@ void test_task_stores_exception_if_function_throws() void test_void_promise() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( void_promise).join(); void_promise(); @@ -1277,8 +1277,8 @@ void test_void_promise() void test_reference_promise() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( reference_promise).join(); reference_promise(); @@ -1286,8 +1286,8 @@ void test_reference_promise() void test_task_returning_void() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( task_returning_void).join(); task_returning_void(); @@ -1295,8 +1295,8 @@ void test_task_returning_void() void test_task_returning_reference() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( task_returning_reference).join(); task_returning_reference(); @@ -1304,8 +1304,8 @@ void test_task_returning_reference() void test_shared_future() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( shared_future).join(); shared_future(); @@ -1313,8 +1313,8 @@ void test_shared_future() void test_copies_of_shared_future_become_ready_together() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( copies_of_shared_future_become_ready_together).join(); copies_of_shared_future_become_ready_together(); @@ -1322,8 +1322,8 @@ void test_copies_of_shared_future_become_ready_together() void test_shared_future_can_be_move_assigned_from_unique_future() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( shared_future_can_be_move_assigned_from_unique_future).join(); shared_future_can_be_move_assigned_from_unique_future(); @@ -1331,8 +1331,8 @@ void test_shared_future_can_be_move_assigned_from_unique_future() void test_shared_future_void() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( shared_future_void).join(); shared_future_void(); @@ -1340,8 +1340,8 @@ void test_shared_future_void() void test_shared_future_ref() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( shared_future_ref).join(); shared_future_ref(); @@ -1349,8 +1349,8 @@ void test_shared_future_ref() void test_can_get_a_second_future_from_a_moved_promise() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( can_get_a_second_future_from_a_moved_promise).join(); can_get_a_second_future_from_a_moved_promise(); @@ -1358,8 +1358,8 @@ void test_can_get_a_second_future_from_a_moved_promise() void test_can_get_a_second_future_from_a_moved_void_promise() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( can_get_a_second_future_from_a_moved_void_promise).join(); can_get_a_second_future_from_a_moved_void_promise(); @@ -1367,8 +1367,8 @@ void test_can_get_a_second_future_from_a_moved_void_promise() #if 0 void test_unique_future_for_move_only_udt() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( unique_future_for_move_only_udt).join(); unique_future_for_move_only_udt(); @@ -1376,8 +1376,8 @@ void test_unique_future_for_move_only_udt() #endif void test_unique_future_for_string() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( unique_future_for_string).join(); unique_future_for_string(); @@ -1385,8 +1385,8 @@ void test_unique_future_for_string() void test_wait_callback() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_callback).join(); wait_callback(); @@ -1394,8 +1394,8 @@ void test_wait_callback() void test_wait_callback_with_timed_wait() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_callback_with_timed_wait).join(); wait_callback_with_timed_wait(); @@ -1403,8 +1403,8 @@ void test_wait_callback_with_timed_wait() void test_wait_callback_for_packaged_task() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_callback_for_packaged_task).join(); wait_callback_for_packaged_task(); @@ -1412,8 +1412,8 @@ void test_wait_callback_for_packaged_task() void test_packaged_task_can_be_moved() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( packaged_task_can_be_moved).join(); packaged_task_can_be_moved(); @@ -1421,8 +1421,8 @@ void test_packaged_task_can_be_moved() void test_destroying_a_promise_stores_broken_promise() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( destroying_a_promise_stores_broken_promise).join(); destroying_a_promise_stores_broken_promise(); @@ -1430,8 +1430,8 @@ void test_destroying_a_promise_stores_broken_promise() void test_destroying_a_packaged_task_stores_broken_promise() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( destroying_a_packaged_task_stores_broken_promise).join(); destroying_a_packaged_task_stores_broken_promise(); @@ -1439,8 +1439,8 @@ void test_destroying_a_packaged_task_stores_broken_promise() void test_wait_for_either_of_two_futures_1() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_two_futures_1).join(); wait_for_either_of_two_futures_1(); @@ -1448,8 +1448,8 @@ void test_wait_for_either_of_two_futures_1() void test_wait_for_either_of_two_futures_2() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_two_futures_2).join(); wait_for_either_of_two_futures_2(); @@ -1457,8 +1457,8 @@ void test_wait_for_either_of_two_futures_2() void test_wait_for_either_of_three_futures_1() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_three_futures_1).join(); wait_for_either_of_three_futures_1(); @@ -1466,8 +1466,8 @@ void test_wait_for_either_of_three_futures_1() void test_wait_for_either_of_three_futures_2() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_three_futures_2).join(); wait_for_either_of_three_futures_2(); @@ -1475,8 +1475,8 @@ void test_wait_for_either_of_three_futures_2() void test_wait_for_either_of_three_futures_3() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_three_futures_3).join(); wait_for_either_of_three_futures_3(); @@ -1484,8 +1484,8 @@ void test_wait_for_either_of_three_futures_3() void test_wait_for_either_of_four_futures_1() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_four_futures_1).join(); wait_for_either_of_four_futures_1(); @@ -1493,8 +1493,8 @@ void test_wait_for_either_of_four_futures_1() void test_wait_for_either_of_four_futures_2() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_four_futures_2).join(); wait_for_either_of_four_futures_2(); @@ -1502,8 +1502,8 @@ void test_wait_for_either_of_four_futures_2() void test_wait_for_either_of_four_futures_3() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_four_futures_3).join(); wait_for_either_of_four_futures_3(); @@ -1511,8 +1511,8 @@ void test_wait_for_either_of_four_futures_3() void test_wait_for_either_of_four_futures_4() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_four_futures_4).join(); wait_for_either_of_four_futures_4(); @@ -1520,8 +1520,8 @@ void test_wait_for_either_of_four_futures_4() void test_wait_for_either_of_five_futures_1() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_five_futures_1).join(); wait_for_either_of_five_futures_1(); @@ -1529,8 +1529,8 @@ void test_wait_for_either_of_five_futures_1() void test_wait_for_either_of_five_futures_2() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_five_futures_2).join(); wait_for_either_of_five_futures_2(); @@ -1538,8 +1538,8 @@ void test_wait_for_either_of_five_futures_2() void test_wait_for_either_of_five_futures_3() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_five_futures_3).join(); wait_for_either_of_five_futures_3(); @@ -1547,8 +1547,8 @@ void test_wait_for_either_of_five_futures_3() void test_wait_for_either_of_five_futures_4() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_five_futures_4).join(); wait_for_either_of_five_futures_4(); @@ -1556,8 +1556,8 @@ void test_wait_for_either_of_five_futures_4() void test_wait_for_either_of_five_futures_5() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_of_five_futures_5).join(); wait_for_either_of_five_futures_5(); @@ -1565,8 +1565,8 @@ void test_wait_for_either_of_five_futures_5() void test_wait_for_either_invokes_callbacks() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_either_invokes_callbacks).join(); wait_for_either_invokes_callbacks(); @@ -1574,8 +1574,8 @@ void test_wait_for_either_invokes_callbacks() #if 0 void test_wait_for_any_from_range() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_any_from_range).join(); wait_for_any_from_range(); @@ -1583,8 +1583,8 @@ void test_wait_for_any_from_range() void test_wait_for_all_from_range() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_all_from_range).join(); wait_for_all_from_range(); @@ -1592,8 +1592,8 @@ void test_wait_for_all_from_range() #endif void test_wait_for_all_two_futures() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_all_two_futures).join(); wait_for_all_two_futures(); @@ -1601,8 +1601,8 @@ void test_wait_for_all_two_futures() void test_wait_for_all_three_futures() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_all_three_futures).join(); wait_for_all_three_futures(); @@ -1610,8 +1610,8 @@ void test_wait_for_all_three_futures() void test_wait_for_all_four_futures() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_all_four_futures).join(); wait_for_all_four_futures(); @@ -1619,8 +1619,8 @@ void test_wait_for_all_four_futures() void test_wait_for_all_five_futures() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( wait_for_all_five_futures).join(); wait_for_all_five_futures(); @@ -1628,8 +1628,8 @@ void test_wait_for_all_five_futures() void test_future_wait() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( future_wait).join(); future_wait(); diff --git a/test/test_generic_locks.cpp b/test/test_generic_locks.cpp index ac08938f..eb974a0d 100644 --- a/test/test_generic_locks.cpp +++ b/test/test_generic_locks.cpp @@ -360,8 +360,8 @@ void try_lock_five() void test_lock_two_uncontended() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_two_uncontended).join(); lock_two_uncontended(); @@ -369,8 +369,8 @@ void test_lock_two_uncontended() void test_lock_five_uncontended() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_five_uncontended).join(); lock_five_uncontended(); @@ -378,8 +378,8 @@ void test_lock_five_uncontended() void test_lock_five_in_range() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_five_in_range).join(); lock_five_in_range(); @@ -387,8 +387,8 @@ void test_lock_five_in_range() void test_lock_ten_in_range() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_ten_in_range).join(); lock_ten_in_range(); @@ -396,8 +396,8 @@ void test_lock_ten_in_range() void test_try_lock_two_uncontended() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_two_uncontended).join(); try_lock_two_uncontended(); @@ -405,8 +405,8 @@ void test_try_lock_two_uncontended() void test_try_lock_two_first_locked() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_two_first_locked).join(); try_lock_two_first_locked(); @@ -414,8 +414,8 @@ void test_try_lock_two_first_locked() void test_try_lock_two_second_locked() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_two_second_locked).join(); try_lock_two_second_locked(); @@ -423,8 +423,8 @@ void test_try_lock_two_second_locked() void test_try_lock_three() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_three).join(); try_lock_three(); @@ -432,8 +432,8 @@ void test_try_lock_three() void test_try_lock_four() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_four).join(); try_lock_four(); @@ -441,8 +441,8 @@ void test_try_lock_four() void test_try_lock_five() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_five).join(); try_lock_five(); diff --git a/test/test_lock.cpp b/test/test_lock.cpp index 70f6e9d6..e51779ef 100644 --- a/test/test_lock.cpp +++ b/test/test_lock.cpp @@ -184,8 +184,8 @@ void swap() void test_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock).join(); lock(); @@ -193,8 +193,8 @@ void test_lock() void test_defer_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( defer_lock).join(); defer_lock(); @@ -202,8 +202,8 @@ void test_defer_lock() void test_adopt_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( adopt_lock).join(); adopt_lock(); @@ -211,8 +211,8 @@ void test_adopt_lock() void test_try_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock).join(); try_lock(); @@ -220,8 +220,8 @@ void test_try_lock() void test_lock_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_twice).join(); lock_twice(); @@ -229,8 +229,8 @@ void test_lock_twice() void test_try_lock_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_twice).join(); try_lock_twice(); @@ -238,8 +238,8 @@ void test_try_lock_twice() void test_unlock_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( unlock_twice).join(); unlock_twice(); @@ -247,8 +247,8 @@ void test_unlock_twice() void test_default_ctor() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( default_ctor).join(); default_ctor(); @@ -256,8 +256,8 @@ void test_default_ctor() void test_lock_concept() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_concept).join(); lock_concept(); @@ -265,8 +265,8 @@ void test_lock_concept() void test_try_lock_concept() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_concept).join(); try_lock_concept(); @@ -274,8 +274,8 @@ void test_try_lock_concept() void test_swap() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( swap).join(); swap(); diff --git a/test/test_manual_reset_event.cpp b/test/test_manual_reset_event.cpp index a7507c83..1890fbbc 100644 --- a/test/test_manual_reset_event.cpp +++ b/test/test_manual_reset_event.cpp @@ -117,8 +117,8 @@ void fn2() void test_wait() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn1).join(); fn1(); @@ -126,8 +126,8 @@ void test_wait() void test_try_wait() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( fn2).join(); fn2(); diff --git a/test/test_mutex.cpp b/test/test_mutex.cpp index 81d6136f..94560619 100644 --- a/test/test_mutex.cpp +++ b/test/test_mutex.cpp @@ -74,8 +74,8 @@ void fn2( stm::mutex & mtx) void test_locking() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber s( & do_test_mutex); BOOST_ASSERT( ! s); @@ -84,8 +84,8 @@ void test_locking() void test_exclusive() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); value1 = 0; value2 = 0; diff --git a/test/test_unique_lock.cpp b/test/test_unique_lock.cpp index cde8be98..31d0886b 100644 --- a/test/test_unique_lock.cpp +++ b/test/test_unique_lock.cpp @@ -184,8 +184,8 @@ void swap() void test_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock).join(); lock(); @@ -193,8 +193,8 @@ void test_lock() void test_defer_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( defer_lock).join(); defer_lock(); @@ -202,8 +202,8 @@ void test_defer_lock() void test_adopt_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( adopt_lock).join(); adopt_lock(); @@ -211,8 +211,8 @@ void test_adopt_lock() void test_try_lock() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock).join(); try_lock(); @@ -220,8 +220,8 @@ void test_try_lock() void test_lock_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_twice).join(); lock_twice(); @@ -229,8 +229,8 @@ void test_lock_twice() void test_try_lock_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_twice).join(); try_lock_twice(); @@ -238,8 +238,8 @@ void test_try_lock_twice() void test_unlock_twice() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( unlock_twice).join(); unlock_twice(); @@ -247,8 +247,8 @@ void test_unlock_twice() void test_default_ctor() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( default_ctor).join(); default_ctor(); @@ -256,8 +256,8 @@ void test_default_ctor() void test_lock_concept() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( lock_concept).join(); lock_concept(); @@ -265,8 +265,8 @@ void test_lock_concept() void test_try_lock_concept() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( try_lock_concept).join(); try_lock_concept(); @@ -274,8 +274,8 @@ void test_try_lock_concept() void test_swap() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); stm::fiber( swap).join(); swap(); diff --git a/test/test_waitfor.cpp b/test/test_waitfor.cpp index d9e4acfb..18d95637 100644 --- a/test/test_waitfor.cpp +++ b/test/test_waitfor.cpp @@ -58,8 +58,8 @@ void f3( int t, int & i) void test_waitfor_all() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); int v1 = 0, v2 = 0; BOOST_CHECK_EQUAL( 0, v1); @@ -77,8 +77,8 @@ void test_waitfor_all() void test_waitfor_any() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); int v1 = 0, v2 = 0; BOOST_CHECK_EQUAL( 0, v1); @@ -97,8 +97,8 @@ void test_waitfor_any() void test_waitfor_any_and_cancel() { - stm::default_scheduler ds; - stm::scheduler::replace( & ds); + stm::round_robin ds; + stm::scheduling_algorithm( & ds); int v1 = 0, v2 = 0; BOOST_CHECK_EQUAL( 0, v1);