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


##########
include/nuttx/atomic.h:
##########
@@ -27,72 +27,158 @@
  * Included Files
  ****************************************************************************/
 
+#include <stdbool.h>
+
 #ifdef __has_include
-#  if defined(__cplusplus) && __has_include(<atomic>)
+#  if __has_include(<atomic>) && defined(__cplusplus)
 extern "C++"
 {
 #    include <atomic>
+#    define ATOMIC_FUNC(f, n) atomic_##f##_explicit
 
-#    define ATOMIC_VAR_INIT(value) (value)
-
-  using std::memory_order;
-  using std::atomic_bool;
-  using std::atomic_char;
-  using std::atomic_schar;
-  using std::atomic_uchar;
-  using std::atomic_short;
-  using std::atomic_ushort;
-  using std::atomic_int;
-  using std::atomic_uint;
-  using std::atomic_long;
-  using std::atomic_ulong;
-  using std::atomic_llong;
-  using std::atomic_ullong;
-
-  using std::atomic_load;
   using std::atomic_load_explicit;
-  using std::atomic_store;
   using std::atomic_store_explicit;
-  using std::atomic_exchange;
   using std::atomic_exchange_explicit;
-  using std::atomic_compare_exchange_strong;
   using std::atomic_compare_exchange_strong_explicit;
-  using std::atomic_compare_exchange_weak;
   using std::atomic_compare_exchange_weak_explicit;
-  using std::atomic_flag_test_and_set;
-  using std::atomic_flag_test_and_set_explicit;
-  using std::atomic_flag_clear;
-  using std::atomic_flag_clear_explicit;
-  using std::atomic_fetch_add;
   using std::atomic_fetch_add_explicit;
-  using std::atomic_fetch_sub;
   using std::atomic_fetch_sub_explicit;
-  using std::atomic_fetch_and;
   using std::atomic_fetch_and_explicit;
-  using std::atomic_fetch_or;
   using std::atomic_fetch_or_explicit;
-  using std::atomic_fetch_xor;
   using std::atomic_fetch_xor_explicit;
+
+  typedef volatile int32_t atomic_t;
+  typedef volatile int64_t atomic64_t;
 }
 #  elif __has_include(<stdatomic.h>) && \
         ((defined(__cplusplus) && __cplusplus >= 201103L) || \
          (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)) && \
          !defined(__STDC_NO_ATOMICS__)
-#    if !(__clang__) && defined(__cplusplus)
+#    if !defined(__clang__) && defined(__cplusplus)

Review Comment:
   let's move line 63/64 here and remove _Atomic



##########
include/nuttx/spinlock.h:
##########
@@ -283,25 +282,7 @@ static inline_function bool
 spin_trylock_wo_note(FAR volatile spinlock_t *lock)
 {
 #ifdef CONFIG_TICKET_SPINLOCK
-  unsigned short ticket =
-    atomic_load((FAR atomic_ushort *)&lock->tickets.next);
-
-  spinlock_t oldval =
-    {
-      {
-        ticket, ticket
-      }
-    };
-
-  spinlock_t newval =
-    {
-      {
-        ticket, ticket + 1
-      }
-    };
-
-  if (!atomic_compare_exchange_strong((FAR atomic_uint *)&lock->value,
-                                      &oldval.value, newval.value))
+  if (!atomic_cmpxchg(&lock->next, &lock->owner, lock->next + 1))

Review Comment:
   ```suggestion
     if (!atomic_cmpxchg(&lock->next, &lock->owner, atomic_read(lock->next) + 
1))
   ```



##########
arch/arm/src/cxd56xx/cxd56_uart0.c:
##########
@@ -115,7 +115,7 @@ static int uart0_open(struct file *filep)
   int stop;
   int ret;
 
-  if (atomic_load(&inode->i_crefs) > 2)
+  if (atomic_read(&inode->i_crefs) > 2)

Review Comment:
   let's modify https://github.com/apache/nuttx/pull/14985 too.



##########
include/nuttx/spinlock.h:
##########
@@ -448,7 +429,7 @@ static inline_function void spin_unlock(FAR volatile 
spinlock_t *lock)
 
 /* bool spin_islocked(FAR spinlock_t lock); */
 #ifdef CONFIG_TICKET_SPINLOCK
-#  define spin_is_locked(l) ((*l).tickets.owner != (*l).tickets.next)
+#  define spin_is_locked(l) ((*l).owner != (*l).next)

Review Comment:
   ```suggestion
   #  define spin_is_locked(l) (atomic_read((*l).owner) != 
atomic_read((*l).next))
   ```



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