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


##########
sched/semaphore/sem_post.c:
##########
@@ -85,19 +87,54 @@ int nxsem_post_slow(FAR sem_t *sem)
 
   flags = enter_critical_section();
 
-  /* Check the maximum allowable value */
+  if (mutex)
+    {
+      /* Mutex post from interrupt context is not allowed */
+
+      DEBUGASSERT(!up_interrupt_context());
+
+      /* Lock the mutex for us by setting the blocking bit */
+
+      mholder = atomic_fetch_or(NXSEM_MHOLDER(sem), NXSEM_MBLOCKS_BIT);
+
+      /* Mutex post from another thread is not allowed, unless
+       * called from nxsem_reset
+       */
+
+      DEBUGASSERT(mholder == (NXSEM_MBLOCKS_BIT | NXSEM_MRESET) ||
+                  (mholder & (~NXSEM_MBLOCKS_BIT)) == nxsched_gettid());
+
+      sem_blocks = NXSEM_MBLOCKS(mholder);
 
-  sem_count = atomic_read(NXSEM_COUNT(sem));
-  do
+      if (!sem_blocks)
+        {
+          if (mholder != NXSEM_MRESET)
+            {
+              mholder = NXSEM_NO_MHOLDER;
+            }
+
+          atomic_set(NXSEM_MHOLDER(sem), mholder);
+        }
+    }
+  else
     {
-      if (sem_count >= SEM_VALUE_MAX)
+      int32_t sem_count;

Review Comment:
   That is original code, why change it?



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