execute events if difference is 0, prevents a busywait

This commit is contained in:
Martin Willi
2008-12-12 09:16:31 +00:00
parent 8006835ec1
commit 3993b91334
+3 -2
View File
@@ -179,7 +179,6 @@ static job_requeue_t schedule(private_scheduler_t * this)
int oldstate;
bool timed = FALSE;
DBG2(DBG_JOB, "waiting for next event...");
this->mutex->lock(this->mutex);
gettimeofday(&now, NULL);
@@ -187,7 +186,7 @@ static job_requeue_t schedule(private_scheduler_t * this)
if ((event = peek_event(this)) != NULL)
{
difference = time_difference(&now, &event->time);
if (difference > 0)
if (difference >= 0)
{
remove_event(this);
this->mutex->unlock(this->mutex);
@@ -196,6 +195,7 @@ static job_requeue_t schedule(private_scheduler_t * this)
free(event);
return JOB_REQUEUE_DIRECT;
}
DBG2(DBG_JOB, "next event in %ldms, waiting", -difference);
timed = TRUE;
}
pthread_cleanup_push((void*)this->mutex->unlock, this->mutex);
@@ -207,6 +207,7 @@ static job_requeue_t schedule(private_scheduler_t * this)
}
else
{
DBG2(DBG_JOB, "no events, waiting");
this->condvar->wait(this->condvar, this->mutex);
}
pthread_setcancelstate(oldstate, NULL);