@@ -196,6 +196,7 @@ int NamedLWLockTrancheRequests = 0;
196196
197197/* points to data in shared memory: */
198198NamedLWLockTranche * NamedLWLockTrancheArray = NULL ;
199+ int * LWLockCounter = NULL ;
199200
200201static void InitializeLWLocks (void );
201202static inline void LWLockReportWaitStart (LWLock * lock );
@@ -397,11 +398,11 @@ LWLockShmemSize(void)
397398 /* Calculate total number of locks needed in the main array. */
398399 numLocks += NumLWLocksForNamedTranches ();
399400
400- /* Space for the LWLock array. */
401- size = mul_size (numLocks , sizeof (LWLockPadded ));
402-
403401 /* Space for dynamic allocation counter, plus room for alignment. */
404- size = add_size (size , sizeof (int ) + LWLOCK_PADDED_SIZE );
402+ size = sizeof (int ) + LWLOCK_PADDED_SIZE ;
403+
404+ /* Space for the LWLock array. */
405+ size = add_size (size , mul_size (numLocks , sizeof (LWLockPadded )));
405406
406407 /* space for named tranches. */
407408 size = add_size (size , mul_size (NamedLWLockTrancheRequests , sizeof (NamedLWLockTranche )));
@@ -423,27 +424,20 @@ CreateLWLocks(void)
423424 if (!IsUnderPostmaster )
424425 {
425426 Size spaceLocks = LWLockShmemSize ();
426- int * LWLockCounter ;
427427 char * ptr ;
428428
429429 /* Allocate space */
430430 ptr = (char * ) ShmemAlloc (spaceLocks );
431431
432- /* Leave room for dynamic allocation of tranches */
432+ /* Initialize the dynamic-allocation counter for tranches */
433+ LWLockCounter = (int * ) ptr ;
434+ * LWLockCounter = LWTRANCHE_FIRST_USER_DEFINED ;
433435 ptr += sizeof (int );
434436
435437 /* Ensure desired alignment of LWLock array */
436438 ptr += LWLOCK_PADDED_SIZE - ((uintptr_t ) ptr ) % LWLOCK_PADDED_SIZE ;
437-
438439 MainLWLockArray = (LWLockPadded * ) ptr ;
439440
440- /*
441- * Initialize the dynamic-allocation counter for tranches, which is
442- * stored just before the first LWLock.
443- */
444- LWLockCounter = (int * ) ((char * ) MainLWLockArray - sizeof (int ));
445- * LWLockCounter = LWTRANCHE_FIRST_USER_DEFINED ;
446-
447441 /* Initialize all LWLocks */
448442 InitializeLWLocks ();
449443 }
574568LWLockNewTrancheId (void )
575569{
576570 int result ;
577- int * LWLockCounter ;
578571
579- LWLockCounter = (int * ) ((char * ) MainLWLockArray - sizeof (int ));
580572 /* We use the ShmemLock spinlock to protect LWLockCounter */
581573 SpinLockAcquire (ShmemLock );
582574 result = (* LWLockCounter )++ ;
0 commit comments