fix schedule sort order

This commit is contained in:
Daniel Larimer 2012-09-23 02:01:27 -04:00
parent 0d5afe86d9
commit dc91979409
5 changed files with 9 additions and 3 deletions

View file

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

View file

@ -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:

View file

@ -135,6 +135,7 @@ namespace fc {
//promise_base* prom;
std::vector<blocked_promise> 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;

View file

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

View file

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