Skip to content

Commit

Permalink
spinlock: add __cplusplus check to avoid build break with C++
Browse files Browse the repository at this point in the history
stdatomic.h is incompatible with C++

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao committed Nov 12, 2023
1 parent d999deb commit 8180951
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions include/nuttx/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

#include <nuttx/irq.h>

#ifdef CONFIG_RW_SPINLOCK
#include <stdatomic.h>
#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
Expand Down Expand Up @@ -117,6 +117,15 @@ typedef union spinlock_u spinlock_t;
* Public Function Prototypes
****************************************************************************/

#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif

/****************************************************************************
* Name: up_testset
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -809,4 +818,10 @@ void write_unlock_irqrestore(FAR rwlock_t *lock, irqstate_t flags);
#endif

#endif /* CONFIG_RW_SPINLOCK */

#undef EXTERN
#if defined(__cplusplus)
}
#endif

#endif /* __INCLUDE_NUTTX_SPINLOCK_H */

0 comments on commit 8180951

Please sign in to comment.