fixed daemon kill before threads are spawned
[strongswan.git] / src / charon / processing / jobs / callback_job.c
index 86aa93c..2cba606 100644 (file)
@@ -56,7 +56,7 @@ struct private_callback_job_t {
        pthread_t thread;
 
        /**
-        * mutex to synchronize thread startup/cancellation
+        * mutex to access jobs interna
         */
        pthread_mutex_t mutex;
 
@@ -121,21 +121,19 @@ static void cancel(private_callback_job_t *this)
 {
        pthread_t thread;
        
-       /* wait until thread has started */
        pthread_mutex_lock(&this->mutex);
-       while (this->thread == 0)
-       {
-               pthread_cond_wait(&this->condvar, &this->mutex);
-       }
        thread = this->thread;
        
        /* terminate its children */
-       this->children->invoke(this->children, offsetof(callback_job_t, cancel));
+       this->children->invoke_offset(this->children, offsetof(callback_job_t, cancel));
        pthread_mutex_unlock(&this->mutex);
        
        /* terminate thread */
-       pthread_cancel(thread);
-       pthread_join(thread, NULL);
+       if (thread)
+       {
+               pthread_cancel(thread);
+               pthread_join(thread, NULL);
+       }
 }
 
 /**