Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wKIKF-000one-3B for pgsql-hackers@arkaria.postgresql.org; Tue, 05 May 2026 16:08:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKIKE-00CrPp-0D for pgsql-hackers@arkaria.postgresql.org; Tue, 05 May 2026 16:08:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wKIKD-00CrOm-2J for pgsql-hackers@lists.postgresql.org; Tue, 05 May 2026 16:08:45 +0000 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wKIKB-00000000fqv-2jFw for pgsql-hackers@postgresql.org; Tue, 05 May 2026 16:08:45 +0000 Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-5102582e23eso40636981cf.1 for ; Tue, 05 May 2026 09:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777997322; x=1778602122; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zD9PD6/O/I+9/Vz6nRl/B7PRhPZzC9Xy8NcpP3QSzFo=; b=cWwWPu5eypkOr/UjV7aEsAEw9gfa319OoUJHYO2Ltr1Jocr4GXKpLqn5AOOSNq6O1m XnjnUPKGW6coOCjqthvzBFpxfrB1ihwZ9vIsid74Lznsqt+Am9aUNqXRQ7XW+HuV5wbz LM0tV7XclvMjzpROKLZClYwvHSnmxGzfWVP7MR/dqB1ysM1fjBYemz/REYyWBHL7mwIe IU3apA4iWTcyX3o+jUI/oKM6jz6W+eGKMtjvzYLt1NAD4uaoL/Z56FXFa1+AOl2wTpTT QSMe9/wDK1V2N5syK8N+PrJxmI6Rab+1h3glu+7HGXdvJuANM3EqyKXB4ewejv/PabdQ IGmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777997322; x=1778602122; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zD9PD6/O/I+9/Vz6nRl/B7PRhPZzC9Xy8NcpP3QSzFo=; b=fhOYfTTO1UC2Ykdf/8G1cMypbqoNMxLiZcdDRECyuur6UDvyNTLQmvI1XcD48526/v Rzf6aT8rRfawRenMLgYU8Jjqa/TVHuQuUOAvxMiJZLI5oFBu4zKreDatllc0JGpabyoC Wabh8+J0WDryS6rmWi1QfOfQmcQ/+inEnAK8JO/S6zM10JEIgfIskXJ5yXkbkEppv+Fn O2exf6Kohs7dl5Qmb8wyWdIfYGtpI9Yih1peLtL9q8aFQWBaoz1pjNuutz3I9lY5AqPO HHWkYN8EXpFGjX6vsza5RKmlaYwtqlFK8+Q1O31y7/QHiXDKHt9pNzeBwyu3XQoQo46f TGPg== X-Gm-Message-State: AOJu0YxQu0Rha5pphKA8zl+jHaQDvS+kzk4ncTLLZmTHpVwTlqvnT7Bp cbptJBfkhQnSUxACWHr9Gh1PUKc3SBJmHMoPzfSDliuWOZ1gQO3D15kg X-Gm-Gg: AeBDietTa+wPBC/32D8eqBkfP6hPYyeRG4n7BfGUorOOKkOErBGyIPgnqWRZOlzwdDV SDR6uofjX/ISnQcdfyTXKeYPZw65yDLV9kGOB9DWOFzvcfkTf8aytlpp7r+xr0Mu2T/goaRwXXz M9hX3hCKV6tMqcp4rJBvwK8Iu74XvVpjFe+OTJccWsJFXEVspIZxZbgi9t6jaWZw1hOumTBl0Hh xFJwKMQOK8O/Id92VgIzt2++O/W2qlkayvYHo06GoTKoGbPECs2bdNnY6i+nX+jiDmW87l1NF5+ a/jox/CXpHmLhw4ICrTytWvbhtkCGPKXQxU/iqjApLsjknpph1/8vUj8AyHcnO61sT7WVaGjfDW 1N7unC99Mid8odwWZ4A4pgEgfSHrJuarPmWgg4PV+Gg7mEecq7BJQHMCWw/xTwWLfAP312fcWTO BA8zuUG1F+Rc3wgZUJctwDDIvzGA79QBsOqtaE/TlCwvY7hVnnad0AZEMTKIkr6gamQK9BlaxaL o87A91nDyAqoeuqdDbO/cU6NDu/oqCe X-Received: by 2002:ac8:5ac8:0:b0:50d:9b07:9c46 with SMTP id d75a77b69052e-5104bef2b99mr222706141cf.33.1777997321520; Tue, 05 May 2026 09:08:41 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5104090a381sm146034111cf.8.2026.05.05.09.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 09:08:40 -0700 (PDT) Date: Tue, 5 May 2026 11:08:38 -0500 From: Nathan Bossart To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: small cleanup for s_lock.h Message-ID: References: <369933.1777933007@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UnKLvPhhsIm7C55J" Content-Disposition: inline In-Reply-To: <369933.1777933007@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --UnKLvPhhsIm7C55J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, May 04, 2026 at 06:16:47PM -0400, Tom Lane wrote: > Nathan Bossart writes: >> I noticed that s_lock.h points to a default implementation of tas() in >> tas.s or s_lock.c, but AFAICT there hasn't been a tas() implementation in >> s_lock.c since commit 718aa43a4e, and commit 25f36066dd seems to have >> removed the last remaining tas.s files. So, I think this is dead code. > > It is, but I think the 0001 patch should be more like > > #if !defined(TAS) > -extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or > - * s_lock.c */ > - > -#define TAS(lock) tas(lock) > +#error "must provide a spinlock implementation" > #endif /* TAS */ > > Perhaps this could be merged with the earlier bit about erroring > if not HAS_TEST_AND_SET. > >> I also noticed that HAS_TEST_AND_SET just means that TAS is defined, so I >> wrote a 0002 that removes it in favor of checking TAS directly. > > I'm pretty much -1 on that; HAS_TEST_AND_SET is clearer than TAS, and > removing it seems quite likely to break someone's code. We could > perhaps collect all the separate instances into this end location: > > #if defined(TAS) > #define HAS_TEST_AND_SET > #else > #error "must provide a spinlock implementation" > #endif /* TAS */ Okay, here's a new version of the patch that I believe addresses both points. -- nathan --UnKLvPhhsIm7C55J Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0001-fix-up-TAS-in-s_lock.h.patch From 0fd70f722bd9e16f82b93bf125e04dac9d599a7e Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 5 May 2026 10:59:19 -0500 Subject: [PATCH v2 1/1] fix up TAS in s_lock.h --- src/include/storage/s_lock.h | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index c9e52511990..5ff863d1da5 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -124,7 +124,6 @@ #ifdef __i386__ /* 32-bit i386 */ -#define HAS_TEST_AND_SET typedef unsigned char slock_t; @@ -194,7 +193,6 @@ spin_delay(void) #ifdef __x86_64__ /* AMD Opteron, Intel EM64T */ -#define HAS_TEST_AND_SET typedef unsigned char slock_t; @@ -249,7 +247,6 @@ spin_delay(void) */ #if defined(__arm__) || defined(__arm) || defined(__aarch64__) #ifdef HAVE_GCC__SYNC_INT32_TAS -#define HAS_TEST_AND_SET #define TAS(lock) tas(lock) @@ -292,7 +289,6 @@ spin_delay(void) /* S/390 and S/390x Linux (32- and 64-bit zSeries) */ #if defined(__s390__) || defined(__s390x__) -#define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -321,7 +317,6 @@ tas(volatile slock_t *lock) * acquire/release semantics. The CPU will treat superfluous members as * NOPs, so it's just code space. */ -#define HAS_TEST_AND_SET typedef unsigned char slock_t; @@ -392,7 +387,6 @@ do \ /* PowerPC */ #if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) -#define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -453,7 +447,6 @@ do \ #if defined(__mips__) && !defined(__sgi) /* non-SGI MIPS */ -#define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -531,10 +524,9 @@ do \ * grounds that that's known to be more likely to work in the ARM ecosystem. * (But we dealt with ARM above.) */ -#if !defined(HAS_TEST_AND_SET) +#if !defined(TAS) #if defined(HAVE_GCC__SYNC_INT32_TAS) -#define HAS_TEST_AND_SET #define TAS(lock) tas(lock) @@ -549,7 +541,6 @@ tas(volatile slock_t *lock) #define S_UNLOCK(lock) __sync_lock_release(lock) #elif defined(HAVE_GCC__SYNC_CHAR_TAS) -#define HAS_TEST_AND_SET #define TAS(lock) tas(lock) @@ -565,7 +556,7 @@ tas(volatile slock_t *lock) #endif /* HAVE_GCC__SYNC_INT32_TAS */ -#endif /* !defined(HAS_TEST_AND_SET) */ +#endif /* !defined(TAS) */ /* @@ -592,12 +583,11 @@ tas(volatile slock_t *lock) * --------------------------------------------------------------------- */ -#if !defined(HAS_TEST_AND_SET) /* We didn't trigger above, let's try here */ +#if !defined(TAS) /* We didn't trigger above, let's try here */ #ifdef _MSC_VER typedef LONG slock_t; -#define HAS_TEST_AND_SET #define TAS(lock) (InterlockedCompareExchange(lock, 1, 0)) #define SPIN_DELAY() spin_delay() @@ -649,11 +639,13 @@ spin_delay(void) #endif -#endif /* !defined(HAS_TEST_AND_SET) */ +#endif /* !defined(TAS) */ /* Blow up if we didn't have any way to do spinlocks */ -#ifndef HAS_TEST_AND_SET +#ifdef TAS +#define HAS_TEST_AND_SET +#else #error PostgreSQL does not have spinlock support on this platform. Please report this to pgsql-bugs@lists.postgresql.org. #endif @@ -697,13 +689,6 @@ extern void s_unlock(volatile slock_t *lock); #define SPIN_DELAY() ((void) 0) #endif /* SPIN_DELAY */ -#if !defined(TAS) -extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or - * s_lock.c */ - -#define TAS(lock) tas(lock) -#endif /* TAS */ - #if !defined(TAS_SPIN) #define TAS_SPIN(lock) TAS(lock) #endif /* TAS_SPIN */ -- 2.50.1 (Apple Git-155) --UnKLvPhhsIm7C55J--