workqueue: make cancel_rearming_delayed_workqueue() work on idle dwork
authorOleg Nesterov <oleg@tv-sign.ru>
Wed, 9 May 2007 09:34:11 +0000 (02:34 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 9 May 2007 19:30:52 +0000 (12:30 -0700)
cancel_rearming_delayed_workqueue(dwork) will hang forever if dwork was not
scheduled, because in that case cancel_delayed_work()->del_timer_sync() never
returns true.

I don't know if there are any callers which may have problems, but this is not
so convenient, and the fix is very simple.

Q: looks like we don't need "struct workqueue_struct *wq" parameter.  If the
timer was aborted successfully, get_wq_data() == wq.  Is it worth to add the
new function?

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/workqueue.c

index 74f3f7825229b679935ce08084a2e3800c4cd5ef..ce72d45c7fd83f4b7f6f9bd81f1eff7b36b550eb 100644 (file)
@@ -569,6 +569,10 @@ EXPORT_SYMBOL(flush_work_keventd);
 void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
                                       struct delayed_work *dwork)
 {
+       /* Was it ever queued ? */
+       if (!get_wq_data(&dwork->work))
+               return;
+
        while (!cancel_delayed_work(dwork))
                flush_workqueue(wq);
 }