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


##########
libs/libc/wqueue/work_cancel.c:
##########
@@ -57,53 +58,78 @@
  *   Zero (OK) on success, a negated errno on failure.  This error may be
  *   reported:
  *
- *   -ENOENT - There is no such work queued.
  *   -EINVAL - An invalid work queue was specified
  *
  ****************************************************************************/
 
-static int work_qcancel(FAR struct usr_wqueue_s *wqueue,
+static int work_qcancel(FAR struct usr_wqueue_s *wqueue, bool sync,
                         FAR struct work_s *work)
 {
-  int ret = -ENOENT;
-  int semcount;
+  pid_t self = gettid();
+  int ret;
 
-  DEBUGASSERT(work != NULL);
+  if (wqueue == NULL || work == NULL)
+    {
+      return -EINVAL;
+    }
 
-  /* Get exclusive access to the work queue */
+  for (; ; )

Review Comment:
   The loop is required for the same multi-worker case as the scheduler 
backend. A worker clears work->worker when it dequeues the item, before 
invoking the callback, so the same work_s may be requeued and dispatched to 
another pthread worker while the first callback is still running.
   
   Each iteration waits for one worker currently using the work_s and then 
rescans the pool. This guarantees that work_cancel_sync_wq() does not return 
while another concurrent callback still uses the same work structure. The 
calling worker is skipped to avoid self-deadlock.



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