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 1wKK1E-000qoW-2f for pgsql-hackers@arkaria.postgresql.org; Tue, 05 May 2026 17:57:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKK1D-00DBBx-2K for pgsql-hackers@arkaria.postgresql.org; Tue, 05 May 2026 17:57:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wKK1D-00DBBn-1R for pgsql-hackers@lists.postgresql.org; Tue, 05 May 2026 17:57:15 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wKK1B-00000000Ls7-1NCi for pgsql-hackers@postgresql.org; Tue, 05 May 2026 17:57:14 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-8b4298d271fso68633016d6.3 for ; Tue, 05 May 2026 10:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778003833; x=1778608633; 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=CmrsQWJkw3h3MAEvsKvX/hD2uNWQVzTETrANPHisKBo=; b=L/Hc1A9SrXioB+TpXfixknZQSofD9QFRnXl04N0biod2WvqIw8mLHc8eUgZm0fZhi9 TzlHuvFlfk6xsz4x0ToMFV2ZKmQgJ8xII1C7Tv8KJpmxF1/2J5+KjzvBY10EbINy05Q3 ExogRCdPEPhiDixgYzjM/fsn1e+SfcSAjPEw5eM+jj5366vaBDtJxoZJllS1QygSWqJU Cq6/h8jT2brrUSeRpz7tKxfngfBMYIVwmRWFzmXXlEMilS6Gbf3a362micH9xDLCJIXr d7jz3XyLieeERGr0SCLzV0zuClgfVbSS7MVDhW2BXIS9/UYFhun9inlUar8SOtxOEy5G ZDCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778003833; x=1778608633; 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=CmrsQWJkw3h3MAEvsKvX/hD2uNWQVzTETrANPHisKBo=; b=kJ/ywWTk5fXFU7WLWz/GNiQ8D/ZC1ayUyOYFaQ86TrS6tUnuQC0z8HtfQcZKfOR2UN LrIiaRg8vuVV/0msOB8HOnxlXwgFMntMfdtAbNtH8QsyFl+ixyNs3q2tpsY8z7NmfD8E EVUyGZldL54SPzmyo/sIYBXexVs8Bk7QpFjjjxDJQ3IZyfiql7ojgIusYSQXRG0NfcP0 dl4OYuRFe4+bOZsfMYYp/N0RxwsUop9DkJpEBRltSpAQzqYxmxy2nCID7zP9HEjakjPJ 0oJ+kaevhQwt43H9nXhZia14vWUsiimd8esVJBso8KpSXfHUazDt/ZpJyHJyKuSr1v0T T0Hg== X-Gm-Message-State: AOJu0Yyl8M7e01PmNEBuBzQ7hETFA8R5C9qn0yxSA95sOfz1SJHVdmSg usCgoIk69280Thk5X0t6tSeUj38AN2EEaiG/4giwVOC59Uwf7mtMN7zzkimbdw== X-Gm-Gg: AeBDieuKz7BucTIcm4qcFZ1tFkoz6PuR5fhG7nrdEvVYGTqCzop15Y26cPA4+0qrp1B 6Jf6uctaxYNQM6b1j6IcGMm0CXhgw7av0hW797SLzGcDClDZm3yhQ46+Bll78fV+VsTZ3WU1iVn t8XgXgHJclPhamwFxaSChPxmGL9zasQUernH0kC4LTeLhRGiNdflZPSQ71UUXLQzIcKLwtM5c1Q TextvQ23SiXmbfMgBsdLsBAo6OT4AYLZCK1uyPck36xkLRHrpW5aE3vG30huTpnhN0uc1qJI60l fqXeC9362GHcU6jH/j1O1Xfihj0L9mQLquD7Ck6qznY8cIqwRIS5Svro0DXWq1xHF7Q054spJiP tZpyNo23HQAjZLEyoQe1No2e5w3Lzbv7bBSlqnazpbhivJTBeGBJdySt/DHECLd6foTOAcT31/W rJm7A+Isb0t6nYvwCPo9IXaOH4bQRKXKlcYj8vzX8ZHuvKEW7do6SLB+1gyCzg8zpSJbJbePp8v Ga99yZaIXSFu7zwT32/IFWD94SShCcaLGLzsMTd4yE= X-Received: by 2002:a0c:e005:0:b0:8ba:2c02:f9d6 with SMTP id 6a1803df08f44-8badc12c50amr60744426d6.35.1778003832875; Tue, 05 May 2026 10:57:12 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b53c6b8123sm152144146d6.35.2026.05.05.10.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 10:57:12 -0700 (PDT) Date: Tue, 5 May 2026 12:57:10 -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> <532705.1778000169@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <532705.1778000169@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, May 05, 2026 at 12:56:09PM -0400, Tom Lane wrote: > After thinking some more I realized that what's confusing us here > is an API-level problem. s_lock.h's header comment says > > * Usually, S_LOCK() is implemented in terms of even lower-level macros > * TAS() and TAS_SPIN(): > > As things stand, we have no platforms where that's not the case, > and so we've lost sight of the fact that the contract shouldn't be > "you must provide TAS()". It should be "you must either provide > S_LOCK(), or provide TAS() to base it on". > > A rough cut as to the right way to do this is attached. The > main loose end here is that it's not very clear what s_lock.c's > s_lock() should do if there's no TAS (and hence no TAS_SPIN). > Maybe we should just not compile that function at all without > TAS; if a platform provides a non-default S_LOCK that needs a > helper function, it's on the platform to supply that helper. That makes sense to me. > Also, after noting that HAS_TEST_AND_SET is referenced nowhere > outside s_lock.h, I'm coming around to your previous position > that it's redundant and we should drop it. This is mainly because > it's not clear to me whether it should be set on a platform that > provides S_LOCK but not TAS. I didn't touch that here though. > > Lastly, I definitely agree now that the file's header comment needs > some work. Maybe this insight helps you with that? (One thing > I noticed is that the ending comment about "Equivalent OS-supplied > mutex routines could be used too" feels pretty obsolete. Maybe > instead, "Equivalent compiler intrinsics are another popular option".) I think it does help, thanks. I'll give it a whirl. -- nathan