work接口

/**

  • 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;
    }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值