Skip to content

Commit

Permalink
lib: sbi: Have spinlock checks return bool
Browse files Browse the repository at this point in the history
spin_lock_check already returned bool in the source file but not in the
header. With some toolchains that causes an error, as it should.

Because it and related functions all essentially return a bool, we can
use this opportunity to change them.

Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
  • Loading branch information
JohnAZoidberg authored and avpatel committed May 14, 2021
1 parent 26998f3 commit f90c4c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/sbi/riscv_locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ typedef struct {
#define DEFINE_SPIN_LOCK(x) \
spinlock_t SPIN_LOCK_INIT(x)

int spin_lock_check(spinlock_t *lock);
bool spin_lock_check(spinlock_t *lock);

int spin_trylock(spinlock_t *lock);
bool spin_trylock(spinlock_t *lock);

void spin_lock(spinlock_t *lock);

Expand Down
6 changes: 3 additions & 3 deletions lib/sbi/riscv_locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <sbi/riscv_barrier.h>
#include <sbi/riscv_locks.h>

static inline int spin_lock_unlocked(spinlock_t lock)
static inline bool spin_lock_unlocked(spinlock_t lock)
{
return lock.owner == lock.next;
}
Expand All @@ -19,7 +19,7 @@ bool spin_lock_check(spinlock_t *lock)
return !spin_lock_unlocked(*lock);
}

int spin_trylock(spinlock_t *lock)
bool spin_trylock(spinlock_t *lock)
{
unsigned long inc = 1u << TICKET_SHIFT;
unsigned long mask = 0xffffu << TICKET_SHIFT;
Expand All @@ -42,7 +42,7 @@ int spin_trylock(spinlock_t *lock)
: "r"(inc), "r"(mask), "I"(TICKET_SHIFT)
: "memory");

return !l0;
return l0 == 0;
}

void spin_lock(spinlock_t *lock)
Expand Down

0 comments on commit f90c4c2

Please sign in to comment.