/**
- cancel_work_sync - cancel a work and wait for it to finish
- @work: the work to cancel
- Cancel @work and wait for its execution to finish. This function
- can be used even if the work re-queues itself or migrates to
- another workqueue. On return from this function, @work is
- guaranteed to be not pending or executing on any CPU.
- cancel_work_sync(&delayed_work->work) must not be used for
- delayed_work’s. Use cancel_delayed_work_sync() instead.
- The caller must ensure that the workqueue on which @work was last
- queued can’t be destroyed before this function returns.
- Return:
- %true if @work was pending, %false otherwise.
*/
// 【取消work,等待它执行完成】
// 【可用于重新入队的work或者迁徙到其他workqueue中的work】
// 【该函数确保返回时,各个CPU上没有挂起或者正在执行的work】
// 【只适用于work,不适用于delayed_work】
// 【 delayed_work 使用 cancel_delayed_work_sync 】
// 【调用者必须确保在此函数返回前,不会destroy该work所在的workqueue】
bool cancel_work_sync(struct work_struct *work)
{
return __cancel_work_timer(work, false);
}
/**
- flush_workqueue - ensure that any scheduled work has run to completion.
- @wq: workqueue to flush
- This function sleeps until all work items which were queued on entry
- have finished execution, but it is not livelocked by new incoming ones.
*/
// 【睡,直到所有已调度的work运行完毕,但后来新来的work不会影响到它】
void flush_workqueue(struct workqueue_struct *wq)
/**
-
flush_work - wait for a work to finish executing the last queueing instance
-
@work: the work to flush
-
Wait until @work has finished execution. @work is guaranteed to be idle
-
on return if it hasn’t been requeued since flush started.
-
Return:
-
%true if flush_work() waited for the work to finish execution,
-
%false if it was already idle.
*/
// 【等待一个work完成执行上次入队的句柄/实例】
// 【函数返回时,确保work是idle状态】
bool flush_work(struct work_struct *work)
{
struct wq_barrier barr;lock_map_acquire(&work->lockdep_map);
lock_map_release(&work->lockdep_map);if (start_flush_work(work, &barr)) {
wait_for_completion(&barr.done);
destroy_work_on_stack(&barr.work);
return true;
} else {
return false;
}
}