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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1f665e3498 sched/wqueue: fix issue about worker can't wake up thread 
before work_thread running
1f665e3498 is described below

commit 1f665e349818d917f5ea8e58c1b36019126f1c15
Author: dongjiuzhu1 <dongjiuz...@xiaomi.com>
AuthorDate: Wed Apr 12 17:48:56 2023 +0800

    sched/wqueue: fix issue about worker can't wake up thread before 
work_thread running
    
    Problem:
    AppBringup task in default priority 240 ->
    board_late_initialize() ->
       some driver called work_queue() ->
          nxsem_post(&(wqueue).sem) failed because sem_count is 0
    
    hp work_thread in default priority 224 ->
          nxsem_wait_uninterruptible(&wqueue->sem);
    
    so hp_work_thread can't wake up, worker can't run immediately.
    
    Signed-off-by: dongjiuzhu1 <dongjiuz...@xiaomi.com>
---
 sched/wqueue/kwork_thread.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c
index 43d966c04f..df80969f7f 100644
--- a/sched/wqueue/kwork_thread.c
+++ b/sched/wqueue/kwork_thread.c
@@ -139,13 +139,6 @@ static int work_thread(int argc, FAR char *argv[])
 
   for (; ; )
     {
-      /* Then process queued work.  work_process will not return until: (1)
-       * there is no further work in the work queue, and (2) semaphore is
-       * posted.
-       */
-
-      nxsem_wait_uninterruptible(&wqueue->sem);
-
       /* And check each entry in the work queue.  Since we have disabled
        * interrupts we know:  (1) we will not be suspended unless we do
        * so ourselves, and (2) there will be no changes to the work queue
@@ -182,6 +175,13 @@ static int work_thread(int argc, FAR char *argv[])
           CALL_WORKER(worker, arg);
           flags = enter_critical_section();
         }
+
+      /* Then process queued work.  work_process will not return until: (1)
+       * there is no further work in the work queue, and (2) semaphore is
+       * posted.
+       */
+
+      nxsem_wait_uninterruptible(&wqueue->sem);
     }
 
   leave_critical_section(flags);

Reply via email to