You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/11/13 01:01:21 UTC

(nuttx) 03/03: spinlock: add __cplusplus check to avoid build break with C++

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 74d698f439e91ea7b869a089bb019ee1c3df26b4
Author: chao an <an...@xiaomi.com>
AuthorDate: Sun Nov 12 21:50:20 2023 +0800

    spinlock: add __cplusplus check to avoid build break with C++
    
    stdatomic.h is incompatible with C++
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 include/nuttx/spinlock.h | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h
index 63c82c2e8d..e0663afda0 100644
--- a/include/nuttx/spinlock.h
+++ b/include/nuttx/spinlock.h
@@ -32,12 +32,21 @@
 
 #include <nuttx/irq.h>
 
-#ifdef CONFIG_RW_SPINLOCK
-#include <stdatomic.h>
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#if defined(CONFIG_RW_SPINLOCK) && !defined(__cplusplus)
+#  include <stdatomic.h>
 typedef atomic_int rwlock_t;
-#define RW_SP_UNLOCKED      0
-#define RW_SP_READ_LOCKED   1
-#define RW_SP_WRITE_LOCKED -1
+#  define RW_SP_UNLOCKED      0
+#  define RW_SP_READ_LOCKED   1
+#  define RW_SP_WRITE_LOCKED -1
 #endif
 
 #ifndef CONFIG_SPINLOCK
@@ -500,7 +509,7 @@ void spin_unlock_irqrestore_wo_note(FAR spinlock_t *lock, irqstate_t flags);
 #  define spin_unlock_irqrestore_wo_note(l, f) up_irq_restore(f)
 #endif
 
-#ifdef CONFIG_RW_SPINLOCK
+#if defined(CONFIG_RW_SPINLOCK) && !defined(__cplusplus)
 
 /****************************************************************************
  * Name: rwlock_init
@@ -808,5 +817,11 @@ void write_unlock_irqrestore(FAR rwlock_t *lock, irqstate_t flags);
 #  define write_unlock_irqrestore(l, f) up_irq_restore(f)
 #endif
 
-#endif /* CONFIG_RW_SPINLOCK */
+#endif /* CONFIG_RW_SPINLOCK && !__cplusplus */
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
 #endif /* __INCLUDE_NUTTX_SPINLOCK_H */