jlaitine commented on code in PR #16194:
URL: https://github.com/apache/nuttx/pull/16194#discussion_r2059041052


##########
sched/semaphore/sem_reset.c:
##########
@@ -76,38 +81,63 @@ int nxsem_reset(FAR sem_t *sem, int16_t count)
 
   flags = enter_critical_section();
 
-  /* A negative count indicates that the negated number of threads are
-   * waiting to take a count from the semaphore.  Loop here, handing
-   * out counts to any waiting threads.
-   */
-
-  while (atomic_read(NXSEM_COUNT(sem)) < 0 && count > 0)
+  if (NXSEM_IS_MUTEX(sem))
     {
-      /* Give out one counting, waking up one of the waiting threads
-       * and, perhaps, kicking off a lot of priority inheritance
-       * logic (REVISIT).
+      /* Support only resetting mutex to not acquired state */
+
+      DEBUGASSERT(count == 1);
+
+      /* Post the mutex until the mutex is not blocking any more. Call post
+       * with semaphore value set to RESET | BLOCKS so we know that it is
+       * ok in this case to call the post from another thread.
        */
 
-      DEBUGVERIFY(nxsem_post(sem));
-      count--;
-    }
+      atomic_set(NXSEM_MHOLDER(sem),
+                 NXSEM_MRESET | NXSEM_MBLOCKS_BIT);
 
-  /* We exit the above loop with either (1) no threads waiting for the
-   * (i.e., with sem->semcount >= 0).  In this case, 'count' holds the
-   * the new value of the semaphore count.  OR (2) with threads still
-   * waiting but all of the semaphore counts exhausted:  The current
-   * value of sem->semcount is already correct in this case.
-   */
+      while (dq_peek(SEM_WAITLIST(sem)) != NULL)
+        {
+          DEBUGVERIFY(nxsem_post(sem));

Review Comment:
   There is special handling in nxsem_post for posting with value "NXSEM_MRESET 
| NXSEM_MBLOCKS_BIT", and the nxsem post returns with the same.
   
   Again, removing the reset would be preferred. But now it works as it did 
before with "nxmutex" code



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