From 42b6dd0ff1f0eed3c67541a27f90be12e6d84c43 Mon Sep 17 00:00:00 2001 From: ligd Date: Tue, 10 Sep 2024 23:46:19 +0800 Subject: [PATCH] wqueue: extend the work_cancel_sync() return value Return 1 to indicate the work was not cancelled. Because it is currently being processed by work thread, but wait for it to finish. Signed-off-by: ligd --- include/nuttx/wqueue.h | 6 ++++-- sched/wqueue/kwork_cancel.c | 31 +++++-------------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index 58162ab88f..a38125446a 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -470,8 +470,10 @@ int work_cancel_wq(FAR struct kwork_wqueue_s *wqueue, * work - The previously queued work structure to cancel * * Returned Value: - * Zero (OK) on success, a negated errno on failure. This error may be - * reported: + * Zero means the work was successfully cancelled. + * One means the work was not cancelled because it is currently being + * processed by work thread, but wait for it to finish. + * A negated errno value is returned on any failure: * * -ENOENT - There is no such work queued. * -EINVAL - An invalid work queue was specified diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index 0a91b3dba5..12186b33b1 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -42,29 +42,6 @@ * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: work_qcancel - * - * Description: - * Cancel previously queued work. This removes work from the work queue. - * After work has been cancelled, it may be requeued by calling - * work_queue() again. - * - * Input Parameters: - * wqueue - The work queue to use - * sync - true: synchronous cancel - * false: asynchronous cancel - * work - The previously queued work structure to cancel - * - * Returned Value: - * Zero (OK) on success, a negated errno on failure. This error may be - * reported: - * - * -ENOENT - There is no such work queued. - * -EINVAL - An invalid work queue was specified - * - ****************************************************************************/ - static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, bool sync, FAR struct work_s *work) { @@ -110,7 +87,7 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, bool sync, wqueue->worker[wndx].pid != nxsched_gettid()) { nxsem_wait_uninterruptible(&wqueue->worker[wndx].wait); - ret = OK; + ret = 1; break; } } @@ -170,8 +147,10 @@ int work_cancel_wq(FAR struct kwork_wqueue_s *wqueue, * work - The previously queued work structure to cancel * * Returned Value: - * Zero (OK) on success, a negated errno on failure. This error may be - * reported: + * Zero means the work was successfully cancelled. + * One means the work was not cancelled because it is currently being + * processed by work thread, but wait for it to finish. + * A negated errno value is returned on any failure: * * -ENOENT - There is no such work queued. * -EINVAL - An invalid work queue was specified