Skip to content

Commit 2425751

Browse files
committed
fix: Mac sim-02 compiler issue
Signed-off-by: TaiJu Wu <[email protected]>
1 parent 76f2011 commit 2425751

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

include/nuttx/spinlock.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#include <nuttx/irq.h>
3434

3535
#ifdef CONFIG_RW_SPINLOCK
36-
typedef int32_t rwlock_t;
36+
#include <stdatomic.h>
37+
typedef atomic_int rwlock_t;
3738
#define RW_SP_UNLOCKED 0
3839
#define RW_SP_READ_LOCKED 1
3940
#define RW_SP_WRITE_LOCKED -1

sched/semaphore/spinlock.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu,
474474

475475
void read_lock(FAR volatile rwlock_t *lock)
476476
{
477-
rwlock_t old;
477+
int32_t old;
478478

479479
while (true)
480480
{
@@ -521,7 +521,7 @@ void read_lock(FAR volatile rwlock_t *lock)
521521

522522
bool read_trylock(FAR volatile rwlock_t *lock)
523523
{
524-
rwlock_t old = atomic_load(lock);
524+
int32_t old = atomic_load(lock);
525525

526526
if (old >= RW_SP_UNLOCKED &&
527527
atomic_compare_exchange_strong(lock, &old, old + 1))
@@ -587,7 +587,7 @@ void read_unlock(FAR volatile rwlock_t *lock)
587587

588588
void write_lock(FAR volatile rwlock_t *lock)
589589
{
590-
rwlock_t zero = RW_SP_UNLOCKED;
590+
int32_t zero = RW_SP_UNLOCKED;
591591

592592
while (!atomic_compare_exchange_strong(lock, &zero, RW_SP_WRITE_LOCKED))
593593
{
@@ -625,7 +625,7 @@ void write_lock(FAR volatile rwlock_t *lock)
625625

626626
bool write_trylock(FAR volatile rwlock_t *lock)
627627
{
628-
rwlock_t zero = RW_SP_UNLOCKED;
628+
int32_t zero = RW_SP_UNLOCKED;
629629

630630
if (!atomic_compare_exchange_strong(lock, &zero, RW_SP_WRITE_LOCKED))
631631
{

0 commit comments

Comments
 (0)