Skip to content

Commit

Permalink
spinlock: Fix ticket_spinlock::is_locked check
Browse files Browse the repository at this point in the history
If multiple waiters call ::lock, next_ticket_ is pushed forward
multiple times.
  • Loading branch information
qookei committed Nov 14, 2024
1 parent 805d23e commit afcba6b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/frg/spinlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct ticket_spinlock {
}

bool is_locked() {
return (__atomic_load_n(&serving_ticket_, __ATOMIC_RELAXED) + 1)
== __atomic_load_n(&next_ticket_, __ATOMIC_RELAXED);
return __atomic_load_n(&serving_ticket_, __ATOMIC_RELAXED)
< __atomic_load_n(&next_ticket_, __ATOMIC_RELAXED);
}

void unlock() {
Expand Down

0 comments on commit afcba6b

Please sign in to comment.