From 3354ee5fd668b00b47920faffe454542a365932f Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Thu, 1 Aug 2024 11:00:20 +1200 Subject: [PATCH v3 2/3] Assert that spinlocks are not double-released. --- src/include/storage/spin.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/include/storage/spin.h b/src/include/storage/spin.h index 326a2711f23..9414c111db8 100644 --- a/src/include/storage/spin.h +++ b/src/include/storage/spin.h @@ -109,6 +109,12 @@ SpinLockInit(volatile slock_t *lock) static inline void SpinLockRelease(volatile slock_t *lock) { + /* + * Use a relaxed load to see that it's currently held. That's OK because + * we expect the calling thread to be the one that set it. + */ + Assert(!pg_atomic_unlocked_test_flag(lock)); + pg_atomic_clear_flag(lock); } -- 2.45.2