Skip to content

Commit f409530

Browse files
Frederic WeisbeckerPeter Zijlstra
authored andcommitted
task_work: Introduce task_work_cancel() again
Re-introduce task_work_cancel(), this time to cancel an actual callback and not *any* callback pointing to a given function. This is going to be needed for perf events event freeing. Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240621091601.18227-3-frederic@kernel.org
1 parent 68cbd41 commit f409530

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

include/linux/task_work.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int task_work_add(struct task_struct *task, struct callback_head *twork,
3131
struct callback_head *task_work_cancel_match(struct task_struct *task,
3232
bool (*match)(struct callback_head *, void *data), void *data);
3333
struct callback_head *task_work_cancel_func(struct task_struct *, task_work_func_t);
34+
bool task_work_cancel(struct task_struct *task, struct callback_head *cb);
3435
void task_work_run(void);
3536

3637
static inline void exit_task_work(struct task_struct *task)

kernel/task_work.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,30 @@ task_work_cancel_func(struct task_struct *task, task_work_func_t func)
136136
return task_work_cancel_match(task, task_work_func_match, func);
137137
}
138138

139+
static bool task_work_match(struct callback_head *cb, void *data)
140+
{
141+
return cb == data;
142+
}
143+
144+
/**
145+
* task_work_cancel - cancel a pending work added by task_work_add()
146+
* @task: the task which should execute the work
147+
* @cb: the callback to remove if queued
148+
*
149+
* Remove a callback from a task's queue if queued.
150+
*
151+
* RETURNS:
152+
* True if the callback was queued and got cancelled, false otherwise.
153+
*/
154+
bool task_work_cancel(struct task_struct *task, struct callback_head *cb)
155+
{
156+
struct callback_head *ret;
157+
158+
ret = task_work_cancel_match(task, task_work_match, cb);
159+
160+
return ret == cb;
161+
}
162+
139163
/**
140164
* task_work_run - execute the works added by task_work_add()
141165
*

0 commit comments

Comments
 (0)