xiaoxiang781216 commented on code in PR #16030:
URL: https://github.com/apache/nuttx/pull/16030#discussion_r2008021310


##########
include/nuttx/semaphore.h:
##########
@@ -59,6 +59,54 @@
      {(c), (f), SEM_WAITLIST_INITIALIZER}
 #endif /* CONFIG_PRIORITY_INHERITANCE */
 
+/* Fast mutex lock/unlock path */
+
+#ifndef CONFIG_LIBC_ARCH_ATOMIC

Review Comment:
   why need check CONFIG_LIBC_ARCH_ATOMIC



##########
include/nuttx/semaphore.h:
##########
@@ -59,6 +59,54 @@
      {(c), (f), SEM_WAITLIST_INITIALIZER}
 #endif /* CONFIG_PRIORITY_INHERITANCE */
 
+/* Fast mutex lock/unlock path */
+
+#ifndef CONFIG_LIBC_ARCH_ATOMIC
+
+#  if defined(CONFIG_PRIORITY_PROTECT) || defined(CONFIG_PRIORITY_INHERITANCE)
+#    define NXSEM_IS_FASTMUTEX(sem)                                       \
+      (((sem)->flags & (SEM_TYPE_MUTEX | SEM_PRIO_MASK)) ==               \
+       (SEM_TYPE_MUTEX | SEM_PRIO_NONE))
+#  else
+#    define NXSEM_IS_FASTMUTEX(sem) ((sem)->flags & SEM_TYPE_MUTEX)
+#  endif
+
+/* Try wait; sets ret to OK or -EAGAIN when success,
+ * -EPERM when fast locking can't be performed
+ */
+
+#  define NXSEM_TRYWAIT_FAST(sem, ret)                                    \

Review Comment:
   can we use inline function to change ret argument to return value



##########
include/nuttx/semaphore.h:
##########
@@ -59,6 +59,54 @@
      {(c), (f), SEM_WAITLIST_INITIALIZER}
 #endif /* CONFIG_PRIORITY_INHERITANCE */
 
+/* Fast mutex lock/unlock path */
+
+#ifndef CONFIG_LIBC_ARCH_ATOMIC
+
+#  if defined(CONFIG_PRIORITY_PROTECT) || defined(CONFIG_PRIORITY_INHERITANCE)
+#    define NXSEM_IS_FASTMUTEX(sem)                                       \
+      (((sem)->flags & (SEM_TYPE_MUTEX | SEM_PRIO_MASK)) ==               \
+       (SEM_TYPE_MUTEX | SEM_PRIO_NONE))
+#  else
+#    define NXSEM_IS_FASTMUTEX(sem) ((sem)->flags & SEM_TYPE_MUTEX)
+#  endif
+
+/* Try wait; sets ret to OK or -EAGAIN when success,
+ * -EPERM when fast locking can't be performed
+ */
+
+#  define NXSEM_TRYWAIT_FAST(sem, ret)                                    \
+    {                                                                     \
+      (ret) = -EPERM;                                                     \
+      if (NXSEM_IS_FASTMUTEX(sem))                                        \
+        {                                                                 \
+          int32_t old = 1;                                                \
+          (ret) = atomic_try_cmpxchg_acquire(NXSEM_COUNT(sem), &old, 0) ? \
+            OK : -EAGAIN;                                                 \
+        }                                                                 \
+    }
+
+/* Post; sets ret to OK when success and -EPERM when
+ * fast posting can't be performed
+ */
+
+#  define NXSEM_POST_FAST(sem, ret)                                       \

Review Comment:
   ditto



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