- fixed event queue for events >36min

This commit is contained in:
Martin Willi
2006-05-30 13:22:46 +00:00
parent 8403b34bd9
commit b93782903f
+5 -18
View File
@@ -85,7 +85,6 @@ static event_t *event_create(timeval_t time, job_t *job)
return this; return this;
} }
typedef struct private_event_queue_t private_event_queue_t; typedef struct private_event_queue_t private_event_queue_t;
/** /**
@@ -118,16 +117,7 @@ struct private_event_queue_t {
}; };
/** /**
* Returns the difference of to timeval structs in microseconds * Returns the difference of to timeval structs in milliseconds
*
* @param end_time end time
* @param start_time start time
*
* @warning this function is also defined in the tester class
* In later improvements, this function can be added to a general
* class type!
*
* @return difference in microseconds (end time - start time)
*/ */
static long time_difference(struct timeval *end_time, struct timeval *start_time) static long time_difference(struct timeval *end_time, struct timeval *start_time)
{ {
@@ -135,14 +125,13 @@ static long time_difference(struct timeval *end_time, struct timeval *start_time
seconds = (end_time->tv_sec - start_time->tv_sec); seconds = (end_time->tv_sec - start_time->tv_sec);
microseconds = (end_time->tv_usec - start_time->tv_usec); microseconds = (end_time->tv_usec - start_time->tv_usec);
return ((seconds * 1000000) + microseconds); return ((seconds * 1000) + microseconds/1000);
} }
/** /**
* Implements event_queue_t.get_count * Implements event_queue_t.get_count
*/ */
static int get_count (private_event_queue_t *this) static int get_count(private_event_queue_t *this)
{ {
int count; int count;
pthread_mutex_lock(&(this->mutex)); pthread_mutex_lock(&(this->mutex));
@@ -181,7 +170,7 @@ static job_t *get(private_event_queue_t *this)
this->list->get_first(this->list,(void **) &next_event); this->list->get_first(this->list,(void **) &next_event);
gettimeofday(&current_time,NULL); gettimeofday(&current_time, NULL);
long difference = time_difference(&current_time,&(next_event->time)); long difference = time_difference(&current_time,&(next_event->time));
if (difference <= 0) if (difference <= 0)
{ {
@@ -192,7 +181,7 @@ static job_t *get(private_event_queue_t *this)
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex)); pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
pthread_cond_timedwait( &(this->condvar), &(this->mutex),&timeout); pthread_cond_timedwait(&(this->condvar), &(this->mutex), &timeout);
/* reset cancellation, remove mutex-unlock handler (without executing) */ /* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL); pthread_setcancelstate(oldstate, NULL);
@@ -208,10 +197,8 @@ static job_t *get(private_event_queue_t *this)
next_event->destroy(next_event); next_event->destroy(next_event);
break; break;
} }
} }
pthread_cond_signal( &(this->condvar)); pthread_cond_signal( &(this->condvar));
pthread_mutex_unlock(&(this->mutex)); pthread_mutex_unlock(&(this->mutex));
return job; return job;