13022591351 commented on code in PR #19982:
URL: https://github.com/apache/nuttx/pull/19982#discussion_r3886221851


##########
libs/libc/wqueue/work_queue.c:
##########
@@ -74,21 +68,56 @@
 
 static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
                        FAR struct work_s *work, worker_t worker,
-                       FAR void *arg, clock_t delay)
+                       FAR void *arg, clock_t delay, bool period)
 {
   FAR struct work_s *curr;
   FAR struct work_s *head;
-  int semcount;
+  int ret;
+
+  if (wqueue == NULL || work == NULL || worker == NULL || delay < 0 ||
+      delay > WDOG_MAX_DELAY)
+    {
+      return -EINVAL;
+    }
 
   /* Get exclusive access to the work queue */
 
-  while (nxmutex_lock(&wqueue->lock) < 0);
+  do
+    {
+      ret = nxmutex_lock(&wqueue->lock);
+    }
+  while (ret < 0);
+
+  if (wqueue->exit)
+    {
+      nxmutex_unlock(&wqueue->lock);
+      return -ESHUTDOWN;
+    }
+
+  /* Remove a previous pending instance before requeueing it. */
+
+  if (work->worker != NULL)
+    {
+      list_delete(&work->node);

Review Comment:
   The list mutation is now protected by wqueue->lock.
   
   I did not call work_cancel_wq() directly because work_qqueue() already holds 
the queue mutex, while the public cancel path acquires the same mutex 
internally. Calling it while holding the lock would deadlock; calling it before 
acquiring the lock would introduce a cancel/requeue race.
   
   Instead, I factored the removal into work_remove(). Its contract requires 
the caller to hold the corresponding queue lock and the work item to belong to 
that queue. Both the queue and cancel paths use this helper, so pending 
replacement remains atomic.
   
   When the removed work was the queue head, the helper result also causes 
work_wake() to run so workers recalculate the next deadline.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to