This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 60c208391126ec3ed07d42f03c80817793157985 Author: chao an <[email protected]> AuthorDate: Wed Oct 28 11:41:28 2026 +0800 sched/wqueue: Fast path pending work insertion Avoid scanning the pending work list when a delayed work item belongs at the head or tail, or when the list is empty. This keeps the common ordered append case out of the locked linear scan while preserving the existing qtime order. Signed-off-by: chao an <[email protected]> --- sched/wqueue/wqueue.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h index 5b210153ab5..9e621da2b94 100644 --- a/sched/wqueue/wqueue.h +++ b/sched/wqueue/wqueue.h @@ -180,10 +180,36 @@ bool work_insert_pending(FAR struct kwork_wqueue_s *wqueue, DEBUGASSERT(wqueue != NULL && work != NULL); + /* Empty list: insert directly as the first pending work. */ + + if (list_is_empty(&wqueue->pending)) + { + list_add_head(&wqueue->pending, &work->node); + return true; + } + /* Insert the work into the wait queue sorted by the expired time. */ head = list_first_entry(&wqueue->pending, struct work_s, node); + /* New earliest expiration: insert at the head and restart the timer. */ + + if (!clock_compare(head->qtime, work->qtime)) + { + list_add_head(&wqueue->pending, &work->node); + return true; + } + + curr = list_last_entry(&wqueue->pending, struct work_s, node); + + /* New latest expiration: append at the tail without scanning. */ + + if (clock_compare(curr->qtime, work->qtime)) + { + list_add_tail(&wqueue->pending, &work->node); + return false; + } + list_for_every_entry(&wqueue->pending, curr, struct work_s, node) { if (!clock_compare(curr->qtime, work->qtime))
