]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
scheduler: Add method to remove all scheduled jobs
authorTobias Brunner <tobias@strongswan.org>
Thu, 5 Mar 2015 09:07:33 +0000 (10:07 +0100)
committerTobias Brunner <tobias@strongswan.org>
Mon, 9 Mar 2015 14:57:57 +0000 (15:57 +0100)
References #840.

src/libstrongswan/processing/scheduler.c
src/libstrongswan/processing/scheduler.h

index 3f1598fc48a93d8a26bf2f4f915f3003406b162b..d9085256102b61a4ca81dff2960f3c0a799a80a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
+ * Copyright (C) 2008-2015 Tobias Brunner
  * Copyright (C) 2005-2006 Martin Willi
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
@@ -300,16 +300,26 @@ METHOD(scheduler_t, schedule_job_ms, void,
        schedule_job_tv(this, job, tv);
 }
 
-METHOD(scheduler_t, destroy, void,
+METHOD(scheduler_t, flush, void,
        private_scheduler_t *this)
 {
        event_t *event;
-       this->condvar->destroy(this->condvar);
-       this->mutex->destroy(this->mutex);
+
+       this->mutex->lock(this->mutex);
        while ((event = remove_event(this)) != NULL)
        {
                event_destroy(event);
        }
+       this->condvar->signal(this->condvar);
+       this->mutex->unlock(this->mutex);
+}
+
+METHOD(scheduler_t, destroy, void,
+       private_scheduler_t *this)
+{
+       flush(this);
+       this->condvar->destroy(this->condvar);
+       this->mutex->destroy(this->mutex);
        free(this->heap);
        free(this);
 }
@@ -328,6 +338,7 @@ scheduler_t * scheduler_create()
                        .schedule_job = _schedule_job,
                        .schedule_job_ms = _schedule_job_ms,
                        .schedule_job_tv = _schedule_job_tv,
+                       .flush = _flush,
                        .destroy = _destroy,
                },
                .heap_size = HEAP_SIZE_DEFAULT,
index abbf74e2cecf0246609a5ad6232ad96f11a9c671..7f91fcc59aa4ea7d22f8d1f19e09cec57cbecde4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Tobias Brunner
+ * Copyright (C) 2009-2015 Tobias Brunner
  * Copyright (C) 2005-2007 Martin Willi
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
@@ -114,6 +114,11 @@ struct scheduler_t {
         */
        u_int (*get_job_load) (scheduler_t *this);
 
+       /**
+        * Remove all scheduled jobs.
+        */
+       void (*flush)(scheduler_t *this);
+
        /**
         * Destroys a scheduler object.
         */