You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2023/01/28 12:45:19 UTC

[nuttx] 01/02: sched/wqueue: semaphore count should be consistent with the number of work entries.

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b9d70365a1cd722018ca4feb3f26b1fa20294465
Author: chao an <an...@xiaomi.com>
AuthorDate: Sat Jan 28 13:24:04 2023 +0800

    sched/wqueue: semaphore count should be consistent with the number of work entries.
    
    The number of work entries will be inconsistent with semaphore count
    if the work is canceled, in extreme case, semaphore count will overflow
    and fallback to 0 the workqueue will stop scheduling the enqueue work.
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 sched/wqueue/kwork_cancel.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c
index 340d861ce5..fd8055ea04 100644
--- a/sched/wqueue/kwork_cancel.c
+++ b/sched/wqueue/kwork_cancel.c
@@ -88,6 +88,12 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue,
       else
         {
           dq_rem((FAR dq_entry_t *)work, &wqueue->q);
+
+          /* Semaphore count should be consistent with the number of
+           * work entries.
+           */
+
+          wqueue->sem.semcount--;
         }
 
       work->worker = NULL;