From afcba6bb576f2cde3486ce388b51672d2ac1a1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20S=C5=82omi=C5=84ski?= Date: Thu, 14 Nov 2024 17:04:16 +0100 Subject: [PATCH] spinlock: Fix ticket_spinlock::is_locked check If multiple waiters call ::lock, next_ticket_ is pushed forward multiple times. --- include/frg/spinlock.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/frg/spinlock.hpp b/include/frg/spinlock.hpp index 310486c..3680775 100644 --- a/include/frg/spinlock.hpp +++ b/include/frg/spinlock.hpp @@ -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() {