diff options
author | Martin Willi <martin@strongswan.org> | 2006-05-30 13:22:46 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2006-05-30 13:22:46 +0000 |
commit | b93782903fb1463ec3bd5fcee325d485a26f85b9 (patch) | |
tree | 004ee571b6e45a5af803154fe510f47870d5b4b1 | |
parent | 8403b34bd9312fd4be99b252c2a805c5a80fe0c7 (diff) | |
download | strongswan-b93782903fb1463ec3bd5fcee325d485a26f85b9.tar.bz2 strongswan-b93782903fb1463ec3bd5fcee325d485a26f85b9.tar.xz |
- fixed event queue for events >36min
-rw-r--r-- | src/charon/queues/event_queue.c | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/src/charon/queues/event_queue.c b/src/charon/queues/event_queue.c index ece9d1513..ea69435c3 100644 --- a/src/charon/queues/event_queue.c +++ b/src/charon/queues/event_queue.c @@ -85,7 +85,6 @@ static event_t *event_create(timeval_t time, job_t *job) return this; } - typedef struct private_event_queue_t private_event_queue_t; /** @@ -118,31 +117,21 @@ struct private_event_queue_t { }; /** - * Returns the difference of to timeval structs in microseconds - * - * @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) + * Returns the difference of to timeval structs in milliseconds */ static long time_difference(struct timeval *end_time, struct timeval *start_time) { long seconds, microseconds; - + seconds = (end_time->tv_sec - start_time->tv_sec); microseconds = (end_time->tv_usec - start_time->tv_usec); - return ((seconds * 1000000) + microseconds); + return ((seconds * 1000) + microseconds/1000); } - /** * 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; pthread_mutex_lock(&(this->mutex)); @@ -161,9 +150,9 @@ static job_t *get(private_event_queue_t *this) event_t * next_event; job_t *job; int oldstate; - + pthread_mutex_lock(&(this->mutex)); - + while (1) { while(this->list->get_count(this->list) == 0) @@ -171,28 +160,28 @@ static job_t *get(private_event_queue_t *this) /* add mutex unlock handler for cancellation, enable cancellation */ pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex)); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - + pthread_cond_wait( &(this->condvar), &(this->mutex)); - + /* reset cancellation, remove mutex-unlock handler (without executing) */ pthread_setcancelstate(oldstate, NULL); pthread_cleanup_pop(0); } - + this->list->get_first(this->list,(void **) &next_event); - - gettimeofday(¤t_time,NULL); + + gettimeofday(¤t_time, NULL); long difference = time_difference(¤t_time,&(next_event->time)); if (difference <= 0) { timeout.tv_sec = next_event->time.tv_sec; - timeout.tv_nsec = next_event->time.tv_usec * 1000; - + timeout.tv_nsec = next_event->time.tv_usec * 1000; + /* add mutex unlock handler for cancellation, enable cancellation */ pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex)); 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) */ pthread_setcancelstate(oldstate, NULL); @@ -202,18 +191,16 @@ static job_t *get(private_event_queue_t *this) { /* event available */ this->list->remove_first(this->list,(void **) &next_event); - + job = next_event->job; - + next_event->destroy(next_event); break; } - } pthread_cond_signal( &(this->condvar)); - pthread_mutex_unlock(&(this->mutex)); - + return job; } |