xiaoxiang781216 commented on code in PR #16231: URL: https://github.com/apache/nuttx/pull/16231#discussion_r2074680361
########## sched/wqueue/wqueue.h: ########## @@ -159,6 +148,65 @@ static inline_function FAR struct kwork_wqueue_s *work_qid2wq(int qid) } } +/**************************************************************************** + * Name: work_insert_pending + * + * Description: + * Internal public function to insert the work to the workqueue. + * Require wqueue != NULL and work != NULL. + * + * Input Parameters: + * wqueue - The work queue. + * work - The work to be inserted. + * + * Returned Value: + * Return whether the work is inserted at the head of the pending queue. + * + ****************************************************************************/ + +static inline_function +bool work_insert_pending(FAR struct kwork_wqueue_s *wqueue, + FAR struct work_s *work) +{ + struct work_s *curr; + + DEBUGASSERT(wqueue != NULL && work != NULL); + + /* Insert the work into the wait queue sorted by the expired time. */ + + list_for_every_entry(&wqueue->pending, curr, struct work_s, node) + { + if (!clock_compare(curr->qtime, work->qtime)) + { + break; + } + } + + /* After the insertion, we do not violate the invariant that + * the wait queue is sorted by the expired time. Because + * curr->qtime > work_qtime. + * In the case of the wqueue is empty, we insert + * the work at the head of the wait queue. + */ + + list_add_before(&curr->node, &work->node); + + return &curr->node == &wqueue->pending; Review Comment: Ok. -- 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