From dc9197940981f775b0cb8c2d07f8dbd47f11a29a Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sun, 23 Sep 2012 02:01:27 -0400 Subject: [PATCH] fix schedule sort order --- include/fc/priority.hpp | 2 ++ include/fc/time.hpp | 1 + src/context.hpp | 1 + src/thread.cpp | 2 +- src/thread_d.hpp | 6 ++++-- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/fc/priority.hpp b/include/fc/priority.hpp index fa5df77..90749ab 100644 --- a/include/fc/priority.hpp +++ b/include/fc/priority.hpp @@ -13,6 +13,8 @@ namespace fc { bool operator < ( const priority& p )const { return value < p.value; } + static priority max() { return priority(10000); } + static priority min() { return priority(-10000); } int value; }; } diff --git a/include/fc/time.hpp b/include/fc/time.hpp index 04b55b0..ff3bd9b 100644 --- a/include/fc/time.hpp +++ b/include/fc/time.hpp @@ -10,6 +10,7 @@ namespace fc { friend microseconds operator + (const microseconds& l, const microseconds& r ) { return microseconds(l._count+r._count); } bool operator==(const microseconds& c)const { return _count == c._count; } + friend bool operator>(const microseconds& a, const microseconds& b){ return a._count > b._count; } microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; } int64_t count()const { return _count; } private: diff --git a/src/context.hpp b/src/context.hpp index bff9ae9..fdef8ba 100644 --- a/src/context.hpp +++ b/src/context.hpp @@ -135,6 +135,7 @@ namespace fc { //promise_base* prom; std::vector blocking_prom; time_point resume_time; + // time_point ready_time; // time that this context was put on ready queue fc::context* next_blocked; fc::context* next; fc::thread* ctx_thread; diff --git a/src/thread.cpp b/src/thread.cpp index aa106b1..7c43d05 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -294,7 +294,7 @@ namespace fc { void thread::notify( const promise_base::ptr& p ) { BOOST_ASSERT(p->ready()); if( !is_current() ) { - this->async( [=](){ notify(p); } ); + this->async( [=](){ notify(p); }, "notify", priority::max() ); return; } // TODO: store a list of blocked contexts with the promise diff --git a/src/thread_d.hpp b/src/thread_d.hpp index 7ff48ee..55c2949 100644 --- a/src/thread_d.hpp +++ b/src/thread_d.hpp @@ -134,12 +134,14 @@ namespace fc { return tmp; } void ready_push_front( const fc::context::ptr& c ) { + // c->ready_time = time_point::now(); c->next = ready_head; ready_head = c; if( !ready_tail ) ready_tail = c; } void ready_push_back( const fc::context::ptr& c ) { + // c->ready_time = time_point::now(); c->next = 0; if( ready_tail ) { ready_tail->next = c; @@ -155,7 +157,7 @@ namespace fc { }; struct task_when_less { bool operator()( task_base* a, task_base* b ) { - return a->_when < b->_when; + return a->_when > b->_when; } }; @@ -358,7 +360,7 @@ namespace fc { if( c->blocking_prom.size() ) { c->timeout_blocking_promises(); } - else { ready_push_back( c ); } + else { ready_push_front( c ); } } return time_point::min(); }