workqueue: add cancel_work()
authorJens Axboe <axboe@fb.com>
Wed, 24 Aug 2016 21:51:50 +0000 (15:51 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 29 Aug 2016 14:13:21 +0000 (08:13 -0600)
Like cancel_delayed_work(), but for regular work.

Signed-off-by: Jens Axboe <axboe@fb.com>
Mehed-by: Tejun Heo <tj@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
include/linux/workqueue.h
kernel/workqueue.c

index 26cc1df280d65ae9e060ae0e9058417621c43d53..fc6e22186405873d1d2cb6c66281f8b53ed0d823 100644 (file)
@@ -442,6 +442,7 @@ extern int schedule_on_each_cpu(work_func_t func);
 int execute_in_process_context(work_func_t fn, struct execute_work *);
 
 extern bool flush_work(struct work_struct *work);
+extern bool cancel_work(struct work_struct *work);
 extern bool cancel_work_sync(struct work_struct *work);
 
 extern bool flush_delayed_work(struct delayed_work *dwork);
index ef071ca73fc325e69adb599e7637358c49cd215b..bd81f039027782b923b99be667caa12142c2bf5d 100644 (file)
@@ -2974,6 +2974,31 @@ bool flush_delayed_work(struct delayed_work *dwork)
 }
 EXPORT_SYMBOL(flush_delayed_work);
 
+static bool __cancel_work(struct work_struct *work, bool is_dwork)
+{
+       unsigned long flags;
+       int ret;
+
+       do {
+               ret = try_to_grab_pending(work, is_dwork, &flags);
+       } while (unlikely(ret == -EAGAIN));
+
+       if (unlikely(ret < 0))
+               return false;
+
+       set_work_pool_and_clear_pending(work, get_work_pool_id(work));
+       local_irq_restore(flags);
+       return ret;
+}
+
+/*
+ * See cancel_delayed_work()
+ */
+bool cancel_work(struct work_struct *work)
+{
+       return __cancel_work(work, false);
+}
+
 /**
  * cancel_delayed_work - cancel a delayed work
  * @dwork: delayed_work to cancel
@@ -2992,20 +3017,7 @@ EXPORT_SYMBOL(flush_delayed_work);
  */
 bool cancel_delayed_work(struct delayed_work *dwork)
 {
-       unsigned long flags;
-       int ret;
-
-       do {
-               ret = try_to_grab_pending(&dwork->work, true, &flags);
-       } while (unlikely(ret == -EAGAIN));
-
-       if (unlikely(ret < 0))
-               return false;
-
-       set_work_pool_and_clear_pending(&dwork->work,
-                                       get_work_pool_id(&dwork->work));
-       local_irq_restore(flags);
-       return ret;
+       return __cancel_work(&dwork->work, true);
 }
 EXPORT_SYMBOL(cancel_delayed_work);