anchao commented on code in PR #16231: URL: https://github.com/apache/nuttx/pull/16231#discussion_r2051672835
########## sched/wqueue/kwork_thread.c: ########## @@ -216,18 +288,49 @@ static int work_thread(int argc, FAR char *argv[]) * posted. */ + /* Check the waiting queue */ + + has_next = false; + + if (!list_is_empty(&wqueue->q)) + { + work = list_first_entry(&wqueue->q, struct work_s, node); + + /* The work thread will go sleep until work->qtime */ + + ticks = work->qtime; + has_next = true; + } + wqueue->wait_count++; spin_unlock_irqrestore(&wqueue->lock, flags); sched_unlock(); + /* Set the earliest expired work delay */ + + if (has_next) + { + /* If the earliest work has already expired. */ + + if (clock_compare(ticks, clock_systime_ticks())) + { + /* Continue the work thread loop. */ + + continue; + } + + /* Else we start a time to wake up the work thread. */ + + wd_start_abstick(&wqueue->timer, ticks, work_timer_expired, Review Comment: We should optimize the current wait strategy and wait only when there are no enqueue works or the timer is started, so that `wait_count` and `sem_post` in this function should be removed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org