Skip to content

Commit

Permalink
fix: Mac sim-02 compiler issue
Browse files Browse the repository at this point in the history
This path just for modify Mac sim-02 issue.
The compiler require the firt paramter of atomic_compare_exchange_strong
is atomic type and second parameter is int type.

Signed-off-by: TaiJu Wu <[email protected]>
  • Loading branch information
TaiJuWu committed Oct 15, 2023
1 parent 7f46c18 commit 78b589f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/nuttx/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include <nuttx/irq.h>

#ifdef CONFIG_RW_SPINLOCK
typedef int32_t rwlock_t;
#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
Expand Down
8 changes: 4 additions & 4 deletions sched/semaphore/spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ void read_lock(FAR volatile rwlock_t *lock)
{
while (true)
{
rwlock_t old = atomic_load(lock);
int old = atomic_load(lock);

if (old <= RW_SP_WRITE_LOCKED)
{
Expand Down Expand Up @@ -521,7 +521,7 @@ bool read_trylock(FAR volatile rwlock_t *lock)
{
while (true)
{
rwlock_t old = atomic_load(lock);
int old = atomic_load(lock);

if (old <= RW_SP_WRITE_LOCKED)
{
Expand Down Expand Up @@ -592,7 +592,7 @@ void read_unlock(FAR volatile rwlock_t *lock)

void write_lock(FAR volatile rwlock_t *lock)
{
rwlock_t zero = RW_SP_UNLOCKED;
int zero = RW_SP_UNLOCKED;

while (!atomic_compare_exchange_strong(lock, &zero, RW_SP_WRITE_LOCKED))
{
Expand Down Expand Up @@ -630,7 +630,7 @@ void write_lock(FAR volatile rwlock_t *lock)

bool write_trylock(FAR volatile rwlock_t *lock)
{
rwlock_t zero = RW_SP_UNLOCKED;
int zero = RW_SP_UNLOCKED;

if (atomic_compare_exchange_strong(lock, &zero, RW_SP_WRITE_LOCKED))
{
Expand Down

0 comments on commit 78b589f

Please sign in to comment.