2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-18 01:52:24 +00:00

update scheduling algorithm as Nad suggested

This commit is contained in:
Oliver Kowalke
2013-12-04 18:58:36 +01:00
parent d518a2177e
commit d03bc6a984
3 changed files with 16 additions and 20 deletions

View File

@@ -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);
};
}}}

View File

@@ -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); }
}}

View File

@@ -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;
}
}}}