- docs updated
[strongswan.git] / Source / charon / queues / event_queue.c
index 6954bf2..741fe14 100644 (file)
@@ -90,7 +90,7 @@ static event_t *event_create(timeval_t time, job_t *job)
 typedef struct private_event_queue_t private_event_queue_t;
 
 /**
- * @brief Private Variables and Functions of event_queue_t class.
+ * Private Variables and Functions of event_queue_t class.
  *
  */
 struct private_event_queue_t {
@@ -189,7 +189,15 @@ static job_t *get(private_event_queue_t *this)
                        timeout.tv_sec = next_event->time.tv_sec;
             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);
+                       
+                       /* reset cancellation, remove mutex-unlock handler (without executing) */
+                       pthread_setcancelstate(oldstate, NULL);
+                       pthread_cleanup_pop(0);
                }
                else
                {
@@ -253,7 +261,7 @@ static void add_absolute(private_event_queue_t *this, job_t *job, timeval_t time
 
                iterator_t * iterator;
 
-               this->list->create_iterator(this->list,&iterator,TRUE);
+               iterator = this->list->create_iterator(this->list,TRUE);
 
                iterator->has_next(iterator);
                /* first element has not to be checked (already done) */
@@ -334,7 +342,7 @@ event_queue_t *event_queue_create()
        this->public.add_relative = (void (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative;
        this->public.destroy = (void (*) (event_queue_t *event_queue)) event_queue_destroy;
 
-       this->list = linked_list_create();;
+       this->list = linked_list_create();
        pthread_mutex_init(&(this->mutex), NULL);
        pthread_cond_init(&(this->condvar), NULL);