Commit 43046b606673c9c991919ff75b980b72541e9ede
1 parent
45242006e1
Exists in
master
and in
7 other branches
workqueue: add 'flush_delayed_work()' to run and wait for delayed work
It basically turns a delayed work into an immediate work, and then waits for it to finish.
Showing 2 changed files with 19 additions and 0 deletions Side-by-side Diff
include/linux/workqueue.h
... | ... | @@ -207,6 +207,7 @@ |
207 | 207 | |
208 | 208 | extern void flush_workqueue(struct workqueue_struct *wq); |
209 | 209 | extern void flush_scheduled_work(void); |
210 | +extern void flush_delayed_work(struct delayed_work *work); | |
210 | 211 | |
211 | 212 | extern int schedule_work(struct work_struct *work); |
212 | 213 | extern int schedule_work_on(int cpu, struct work_struct *work); |
kernel/workqueue.c
... | ... | @@ -640,6 +640,24 @@ |
640 | 640 | EXPORT_SYMBOL(schedule_delayed_work); |
641 | 641 | |
642 | 642 | /** |
643 | + * flush_delayed_work - block until a dwork_struct's callback has terminated | |
644 | + * @dwork: the delayed work which is to be flushed | |
645 | + * | |
646 | + * Any timeout is cancelled, and any pending work is run immediately. | |
647 | + */ | |
648 | +void flush_delayed_work(struct delayed_work *dwork) | |
649 | +{ | |
650 | + if (del_timer(&dwork->timer)) { | |
651 | + struct cpu_workqueue_struct *cwq; | |
652 | + cwq = wq_per_cpu(keventd_wq, get_cpu()); | |
653 | + __queue_work(cwq, &dwork->work); | |
654 | + put_cpu(); | |
655 | + } | |
656 | + flush_work(&dwork->work); | |
657 | +} | |
658 | +EXPORT_SYMBOL(flush_delayed_work); | |
659 | + | |
660 | +/** | |
643 | 661 | * schedule_delayed_work_on - queue work in global workqueue on CPU after delay |
644 | 662 | * @cpu: cpu to use |
645 | 663 | * @dwork: job to be done |