Commit f72b8792 authored by Jens Axboe's avatar Jens Axboe

workqueue: add cancel_work()

Like cancel_delayed_work(), but for regular work.
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
Mehed-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarTejun Heo <tj@kernel.org>
parent 3eab887a
...@@ -442,6 +442,7 @@ extern int schedule_on_each_cpu(work_func_t func); ...@@ -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 *); int execute_in_process_context(work_func_t fn, struct execute_work *);
extern bool flush_work(struct work_struct *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 cancel_work_sync(struct work_struct *work);
extern bool flush_delayed_work(struct delayed_work *dwork); extern bool flush_delayed_work(struct delayed_work *dwork);
......
...@@ -2974,6 +2974,31 @@ bool flush_delayed_work(struct delayed_work *dwork) ...@@ -2974,6 +2974,31 @@ bool flush_delayed_work(struct delayed_work *dwork)
} }
EXPORT_SYMBOL(flush_delayed_work); 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 * cancel_delayed_work - cancel a delayed work
* @dwork: delayed_work to cancel * @dwork: delayed_work to cancel
...@@ -2992,20 +3017,7 @@ EXPORT_SYMBOL(flush_delayed_work); ...@@ -2992,20 +3017,7 @@ EXPORT_SYMBOL(flush_delayed_work);
*/ */
bool cancel_delayed_work(struct delayed_work *dwork) bool cancel_delayed_work(struct delayed_work *dwork)
{ {
unsigned long flags; return __cancel_work(&dwork->work, true);
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;
} }
EXPORT_SYMBOL(cancel_delayed_work); EXPORT_SYMBOL(cancel_delayed_work);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment