pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
Subject: [PATCH v2 1/2] Detect unlocking an unlocked spinlock
Date: Mon, 29 Jul 2024 09:48:26 -0700

Author:
Reviewed-by:
Discussion: https://postgr.es/m/20240729164026.yurg37tej34o76uk@awork3.anarazel.de
Backpatch:
---
 src/include/storage/spin.h | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

inline patch 1: src/include/storage/spin.h (+16/-1 lines) download inline-1.patchdiff --git a/src/include/storage/spin.h b/src/include/storage/spin.h index c0679c59992..7ec32cd816a 100644 --- a/src/include/storage/spin.h +++ b/src/include/storage/spin.h @@ -61,7 +61,22 @@ #define SpinLockAcquire(lock) S_LOCK(lock) -#define SpinLockRelease(lock) S_UNLOCK(lock) +static inline void +SpinLockRelease(volatile slock_t *lock) +{ + /* + * Check that this backend actually held the spinlock. Implemented as a + * static inline to avoid multiple-evaluation hazards. + * + * Can't assert when using the semaphore fallback implementation - it + * doesn't implement S_LOCK_FREE() - but the fallback triggers failures in + * the case of double-release on its own. + */ +#ifdef HAVE_SPINLOCKS + Assert(!S_LOCK_FREE(lock)); +#endif + S_UNLOCK(lock); +} #define SpinLockFree(lock) S_LOCK_FREE(lock) -- 2.45.2.746.g06e570c0df.dirty
--fx3sz6dtlxai2igx Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0002-Detect-many-uses-of-uninitialized-spinlocks-on-x8.patch"

Message-ID: <no-message-id-25685@localhost>
Permalink:  ../no-message-id-25685@localhost/
Also on:    postgresql.org/message-id/no-message-id-25685@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: [PATCH v2 1/2] Detect unlocking an unlocked spinlock
  In-Reply-To: <no-message-id-25685@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox