condvar_t *condvar;
};
-/**
- * Compares two timevals, return >0 if a > b, <0 if a < b and =0 if equal
- */
-static int timeval_cmp(timeval_t *a, timeval_t *b)
-{
- if (a->tv_sec > b->tv_sec)
- {
- return 1;
- }
- if (a->tv_sec < b->tv_sec)
- {
- return -1;
- }
- if (a->tv_usec > b->tv_usec)
- {
- return 1;
- }
- if (a->tv_usec < b->tv_usec)
- {
- return -1;
- }
- return 0;
-}
-
/**
* Returns the top event without removing it. Returns NULL if the heap is empty.
*/
static event_t *remove_event(private_scheduler_t *this)
{
event_t *event, *top;
+
if (!this->event_count)
{
return NULL;
if (--this->event_count > 1)
{
- /* seep down the top event */
u_int position = 1;
+
+ /* seep down the top event */
while ((position << 1) <= this->event_count)
{
u_int child = position << 1;
if ((child + 1) <= this->event_count &&
- timeval_cmp(&this->heap[child + 1]->time,
- &this->heap[child]->time) < 0)
+ timercmp(&this->heap[child + 1]->time,
+ &this->heap[child]->time, <))
{
/* the "right" child is smaller */
child++;
}
- if (timeval_cmp(&top->time, &this->heap[child]->time) <= 0)
+ if (!timercmp(&top->time, &this->heap[child]->time, >))
{
/* the top event fires before the smaller of the two children,
* stop */
if ((event = peek_event(this)) != NULL)
{
- if (timeval_cmp(&now, &event->time) >= 0)
+ if (!timercmp(&now, &event->time, <))
{
remove_event(this);
this->mutex->unlock(this->mutex);
private_scheduler_t *this)
{
int count;
+
this->mutex->lock(this->mutex);
count = this->event_count;
this->mutex->unlock(this->mutex);
position = this->event_count;
/* then bubble it up */
- while (position > 1 && timeval_cmp(&this->heap[position >> 1]->time,
- &event->time) > 0)
+ while (position > 1 &&
+ timercmp(&this->heap[position >> 1]->time, &event->time, >))
{
/* parent has to be fired after the new event, move up */
this->heap[position] = this->heap[position >> 1];
return &this->public;
}
-