watcher: Don't wait for running callback once watcher thread cancelled
authorMartin Willi <martin@revosec.ch>
Mon, 10 Mar 2014 09:48:27 +0000 (10:48 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 7 May 2014 12:13:34 +0000 (14:13 +0200)
During shutdown, waiting for callbacks might never complete, as queued
callbacks might not get executed under certain conditions. Not the clean fix,
but works good enough for now.

Seen on Windows in vici tests.

src/libstrongswan/processing/watcher.c

index a0b5529..0990564 100644 (file)
@@ -50,6 +50,11 @@ struct private_watcher_t {
        bool pending;
 
        /**
+        * Is watcher running?
+        */
+       bool running;
+
+       /**
         * Lock to access FD list
         */
        mutex_t *mutex;
@@ -225,6 +230,7 @@ static void activate_all(private_watcher_t *this)
                entry->in_callback = 0;
        }
        enumerator->destroy(enumerator);
+       this->running = FALSE;
        this->condvar->broadcast(this->condvar);
        this->mutex->unlock(this->mutex);
 }
@@ -373,6 +379,7 @@ METHOD(watcher_t, add, void,
        this->fds->insert_last(this->fds, entry);
        if (this->fds->get_count(this->fds) == 1)
        {
+               this->running = TRUE;
                lib->processor->queue_job(lib->processor,
                        (job_t*)callback_job_create_with_prio((void*)watch, this,
                                NULL, (callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
@@ -400,7 +407,7 @@ METHOD(watcher_t, remove_, void,
                {
                        if (entry->fd == fd)
                        {
-                               if (entry->in_callback)
+                               if (this->running && entry->in_callback)
                                {
                                        is_in_callback = TRUE;
                                        break;