Make LWLockCounter a global variable.
authorNathan Bossart <nathan@postgresql.org>
Fri, 29 Aug 2025 17:13:37 +0000 (12:13 -0500)
committerNathan Bossart <nathan@postgresql.org>
Fri, 29 Aug 2025 17:13:37 +0000 (12:13 -0500)
commit67fcf48c3bb3cc3cf51788332701ffb694fb108b
tree588d2cf1d323ce126875f32c5f8c3830bdf86c2f
parent66fa3b5eef6e4764a3beb097ecc9e04b6d956bc9
Make LWLockCounter a global variable.

Using the LWLockCounter requires first calculating its address in
shared memory like this:

LWLockCounter = (int *) ((char *) MainLWLockArray - sizeof(int));

Commit 82e861fbe1 started this trend in order to fix EXEC_BACKEND
builds, but it could also be fixed by adding it to the
BackendParameters struct.  The current approach is somewhat
difficult to follow, so this commit switches to the latter.  While
at it, swap around the code in LWLockShmemSize() to match the order
of assignments in CreateLWLocks() for added readability.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/aLDLnan9gNCS9fHx%40nathan
src/backend/postmaster/launch_backend.c
src/backend/storage/lmgr/lwlock.c
src/include/storage/lwlock.h