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


##########
include/nuttx/spinlock.h:
##########
@@ -633,19 +633,28 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t 
*lock)
  ****************************************************************************/
 
 #ifdef CONFIG_SPINLOCK
-#  define spin_trylock_irqsave_wo_note(l, f) \
-({ \
-  f = up_irq_save(); \
-  spin_trylock_wo_note(l) ? \
-  true : ({ up_irq_restore(f); false; }); \
-})
+static inline_function
+bool spin_trylock_irqsave_wo_note(FAR volatile spinlock_t *lock,
+                                  irqstate_t *flags)
+{
+  *flags = up_irq_save();
+
+  if (!spin_trylock_wo_note(lock))
+    {
+      up_irq_restore(*flags);
+      return false;
+    }
+
+  return true;
+}
 #else
-#  define spin_trylock_irqsave_wo_note(l, f) \
-({ \
-  (void)(l); \
-  f = up_irq_save(); \
-  true; \
-})
+static inline_function
+bool spin_trylock_irqsave_wo_note(FAR volatile spinlock_t *lock,
+                                  irqstate_t *flags)

Review Comment:
   ```suggestion
                                     FAR irqstate_t *flags)
   ```



##########
include/nuttx/spinlock.h:
##########
@@ -669,19 +678,26 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t 
*lock)
  ****************************************************************************/
 
 #ifdef CONFIG_SPINLOCK
-#  define spin_trylock_irqsave(l, f) \
-({ \
-  f = up_irq_save(); \
-  spin_trylock(l) ? \
-  true : ({ up_irq_restore(f); false; }); \
-})
+static inline_function
+bool spin_trylock_irqsave(FAR volatile spinlock_t *lock, irqstate_t *flags)

Review Comment:
   ```suggestion
   bool spin_trylock_irqsave(FAR volatile spinlock_t *lock, FAR irqstate_t 
*flags)
   ```



##########
include/nuttx/spinlock.h:
##########
@@ -633,19 +633,28 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t 
*lock)
  ****************************************************************************/
 
 #ifdef CONFIG_SPINLOCK
-#  define spin_trylock_irqsave_wo_note(l, f) \
-({ \
-  f = up_irq_save(); \
-  spin_trylock_wo_note(l) ? \
-  true : ({ up_irq_restore(f); false; }); \
-})
+static inline_function
+bool spin_trylock_irqsave_wo_note(FAR volatile spinlock_t *lock,
+                                  irqstate_t *flags)

Review Comment:
   ```suggestion
                                     FAR irqstate_t *flags)
   ```



##########
include/nuttx/spinlock.h:
##########
@@ -669,19 +678,26 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t 
*lock)
  ****************************************************************************/
 
 #ifdef CONFIG_SPINLOCK
-#  define spin_trylock_irqsave(l, f) \
-({ \
-  f = up_irq_save(); \
-  spin_trylock(l) ? \
-  true : ({ up_irq_restore(f); false; }); \
-})
+static inline_function
+bool spin_trylock_irqsave(FAR volatile spinlock_t *lock, irqstate_t *flags)
+{
+  *flags = up_irq_save();
+
+  if (!spin_trylock(lock))
+    {
+      up_irq_restore(*flags);
+      return false;
+    }
+
+  return true;
+}
 #else
-#  define spin_trylock_irqsave(l, f) \
-({ \
-  (void)(l); \
-  f = up_irq_save(); \
-  true; \
-})
+static inline_function
+bool spin_trylock_irqsave(FAR volatile spinlock_t *lock, irqstate_t *flags)

Review Comment:
   ```suggestion
   bool spin_trylock_irqsave(FAR volatile spinlock_t *lock, FAR irqstate_t 
*flags)
   ```



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