From d03bc6a984bf4e375b4629e7345eb1416487de8e Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 4 Dec 2013 18:58:36 +0100 Subject: [PATCH] update scheduling algorithm as Nad suggested --- include/boost/fiber/detail/scheduler.hpp | 3 ++- include/boost/fiber/operations.hpp | 4 ++-- src/detail/scheduler.cpp | 29 ++++++++++-------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/boost/fiber/detail/scheduler.hpp b/include/boost/fiber/detail/scheduler.hpp index 4324e823..d6c9075b 100644 --- a/include/boost/fiber/detail/scheduler.hpp +++ b/include/boost/fiber/detail/scheduler.hpp @@ -31,6 +31,7 @@ namespace detail { class scheduler : private noncopyable { private: + static thread_specific_ptr< algorithm > default_algo_; static thread_specific_ptr< algorithm > instance_; public: @@ -44,7 +45,7 @@ public: static algorithm * instance(); - static algorithm * replace( algorithm * other); + static void replace( algorithm * other); }; }}} diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index ea161b1b..b59ce6fa 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -69,8 +69,8 @@ void thread_affinity( bool req) BOOST_NOEXCEPT namespace fibers { inline -algorithm * set_scheduling_algorithm( algorithm * al) -{ return detail::scheduler::replace( al); } +void set_scheduling_algorithm( algorithm * al) +{ detail::scheduler::replace( al); } }} diff --git a/src/detail/scheduler.cpp b/src/detail/scheduler.cpp index 6c030f97..b9bdecc7 100644 --- a/src/detail/scheduler.cpp +++ b/src/detail/scheduler.cpp @@ -17,9 +17,11 @@ namespace boost { namespace fibers { namespace detail { -static void cleanup_function( algorithm *) {} +static void deleter_fn( algorithm * algo) { delete algo; } +static void null_deleter_fn( algorithm *) {} -thread_specific_ptr< algorithm > scheduler::instance_( cleanup_function); +thread_specific_ptr< algorithm > scheduler::default_algo_( deleter_fn); +thread_specific_ptr< algorithm > scheduler::instance_( null_deleter_fn); notify::ptr_t scheduler::make_notification( main_notifier & n) BOOST_NOEXCEPT { @@ -31,27 +33,20 @@ scheduler::make_notification( main_notifier & n) BOOST_NOEXCEPT { algorithm * scheduler::instance() { -#if ! defined(BOOST_FIBERS_DONT_USE_DEFAULT_SCHEDULER) - if ( ! instance_.get() ) instance_.reset( new round_robin() ); -#else - BOOST_ASSERT( instance_.get() ); -#endif + if ( ! instance_.get() ) + { + default_algo_.reset( new round_robin() ); + instance_.reset( default_algo_.get() ); + } return instance_.get(); } -algorithm * +void scheduler::replace( algorithm * other) { - algorithm * old = instance_.release(); + BOOST_ASSERT( other); + instance_.reset( other); -#if ! defined(BOOST_FIBERS_DONT_USE_DEFAULT_SCHEDULER) - if ( dynamic_cast< round_robin * >( old) ) - { - delete old; - old = 0; - } -#endif - return old; } }}}