workqueue: add 'flush_delayed_work()' to run and wait for delayed work
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 14 Oct 2009 16:16:42 +0000 (09:16 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 14 Oct 2009 16:16:42 +0000 (09:16 -0700)
It basically turns a delayed work into an immediate work, and then waits
for it to finish.

include/linux/workqueue.h
kernel/workqueue.c

index 7ef0c7b94f31f02781c873733161b36066b18ff7..cf24c20de9e48e43a4712722196aad8555207d8c 100644 (file)
@@ -207,6 +207,7 @@ extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
 
 extern void flush_workqueue(struct workqueue_struct *wq);
 extern void flush_scheduled_work(void);
+extern void flush_delayed_work(struct delayed_work *work);
 
 extern int schedule_work(struct work_struct *work);
 extern int schedule_work_on(int cpu, struct work_struct *work);
index addfe2df93b13d8982235054d986c1d059fc0894..ccefe574dcf7f93b99cc3bb8b415096111a37395 100644 (file)
@@ -639,6 +639,24 @@ int schedule_delayed_work(struct delayed_work *dwork,
 }
 EXPORT_SYMBOL(schedule_delayed_work);
 
+/**
+ * flush_delayed_work - block until a dwork_struct's callback has terminated
+ * @dwork: the delayed work which is to be flushed
+ *
+ * Any timeout is cancelled, and any pending work is run immediately.
+ */
+void flush_delayed_work(struct delayed_work *dwork)
+{
+       if (del_timer(&dwork->timer)) {
+               struct cpu_workqueue_struct *cwq;
+               cwq = wq_per_cpu(keventd_wq, get_cpu());
+               __queue_work(cwq, &dwork->work);
+               put_cpu();
+       }
+       flush_work(&dwork->work);
+}
+EXPORT_SYMBOL(flush_delayed_work);
+
 /**
  * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
  * @cpu: cpu to use