Fix-Point commented on code in PR #16231:
URL: https://github.com/apache/nuttx/pull/16231#discussion_r2074631337


##########
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:
   We can check if the `curr_node` is the list, which is cache-friendly and can 
reduce one memory access comparing to call `list_is_head(&wqueue->pending, 
&work->node)`.



##########
sched/wqueue/kwork_cancel.c:
##########
@@ -89,6 +109,7 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, 
bool sync,
     }
 
   spin_unlock_irqrestore(&wqueue->lock, flags);
+

Review Comment:
   Done.



-- 
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

Reply via email to