Use macros for calculating LWLock offset

Started by japinabout 5 years ago4 messages
#1japin
japinli@hotmail.com
1 attachment(s)

Hi,

In the lwlock.c, InitializeLWLocks() calculate the LWLock offset by
itself (c319991bcad),
however, there are macros defined in lwlock.h, I think, we can use the
macros.

diff --git a/src/backend/storage/lmgr/lwlock.c 
b/src/backend/storage/lmgr/lwlock.c
index 2fa90cc095..108e652179 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -525,18 +525,17 @@ InitializeLWLocks(void)
                 LWLockInitialize(&lock->lock, id);
         /* Initialize buffer mapping LWLocks in main array */
-       lock = MainLWLockArray + NUM_INDIVIDUAL_LWLOCKS;
+       lock = MainLWLockArray + BUFFER_MAPPING_LWLOCK_OFFSET;
         for (id = 0; id < NUM_BUFFER_PARTITIONS; id++, lock++)
                 LWLockInitialize(&lock->lock, LWTRANCHE_BUFFER_MAPPING);
         /* Initialize lmgrs' LWLocks in main array */
-       lock = MainLWLockArray + NUM_INDIVIDUAL_LWLOCKS + 
NUM_BUFFER_PARTITIONS;
+       lock = MainLWLockArray + LOCK_MANAGER_LWLOCK_OFFSET;
         for (id = 0; id < NUM_LOCK_PARTITIONS; id++, lock++)
                 LWLockInitialize(&lock->lock, LWTRANCHE_LOCK_MANAGER);
         /* Initialize predicate lmgrs' LWLocks in main array */
-       lock = MainLWLockArray + NUM_INDIVIDUAL_LWLOCKS +
-               NUM_BUFFER_PARTITIONS + NUM_LOCK_PARTITIONS;
+       lock = MainLWLockArray + PREDICATELOCK_MANAGER_LWLOCK_OFFSET;
         for (id = 0; id < NUM_PREDICATELOCK_PARTITIONS; id++, lock++)
                 LWLockInitialize(&lock->lock, 
LWTRANCHE_PREDICATE_LOCK_MANAGER);

--
Best regards
Japin Li

Attachments:

lwlock-offset.patchtext/x-patch; charset=UTF-8; name=lwlock-offset.patchDownload
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 2fa90cc095..108e652179 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -525,18 +525,17 @@ InitializeLWLocks(void)
 		LWLockInitialize(&lock->lock, id);
 
 	/* Initialize buffer mapping LWLocks in main array */
-	lock = MainLWLockArray + NUM_INDIVIDUAL_LWLOCKS;
+	lock = MainLWLockArray + BUFFER_MAPPING_LWLOCK_OFFSET;
 	for (id = 0; id < NUM_BUFFER_PARTITIONS; id++, lock++)
 		LWLockInitialize(&lock->lock, LWTRANCHE_BUFFER_MAPPING);
 
 	/* Initialize lmgrs' LWLocks in main array */
-	lock = MainLWLockArray + NUM_INDIVIDUAL_LWLOCKS + NUM_BUFFER_PARTITIONS;
+	lock = MainLWLockArray + LOCK_MANAGER_LWLOCK_OFFSET;
 	for (id = 0; id < NUM_LOCK_PARTITIONS; id++, lock++)
 		LWLockInitialize(&lock->lock, LWTRANCHE_LOCK_MANAGER);
 
 	/* Initialize predicate lmgrs' LWLocks in main array */
-	lock = MainLWLockArray + NUM_INDIVIDUAL_LWLOCKS +
-		NUM_BUFFER_PARTITIONS + NUM_LOCK_PARTITIONS;
+	lock = MainLWLockArray + PREDICATELOCK_MANAGER_LWLOCK_OFFSET;
 	for (id = 0; id < NUM_PREDICATELOCK_PARTITIONS; id++, lock++)
 		LWLockInitialize(&lock->lock, LWTRANCHE_PREDICATE_LOCK_MANAGER);
 
#2Michael Paquier
michael@paquier.xyz
In reply to: japin (#1)
Re: Use macros for calculating LWLock offset

On Thu, Nov 19, 2020 at 03:39:51PM +0800, japin wrote:

In the lwlock.c, InitializeLWLocks() calculate the LWLock offset by itself
(c319991bcad),
however, there are macros defined in lwlock.h, I think, we can use the
macros.

I agree that this makes this code a bit cleaner, so let's use those
macros. Others may have some comments here, so let's wait a bit
first.
--
Michael

#3Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#2)
Re: Use macros for calculating LWLock offset

On Fri, Nov 20, 2020 at 03:25:50PM +0900, Michael Paquier wrote:

I agree that this makes this code a bit cleaner, so let's use those
macros. Others may have some comments here, so let's wait a bit
first.

Got this one committed as of d03d754.
--
Michael

#4Li Japin
japinli@hotmail.com
In reply to: Michael Paquier (#3)
Re: Use macros for calculating LWLock offset

Thanks!

On Nov 24, 2020, at 11:51 AM, Michael Paquier <michael@paquier.xyz<mailto:michael@paquier.xyz>> wrote:

On Fri, Nov 20, 2020 at 03:25:50PM +0900, Michael Paquier wrote:
I agree that this makes this code a bit cleaner, so let's use those
macros. Others may have some comments here, so let's wait a bit
first.

Got this one committed as of d03d754.

Michael

--
Best regards
Japin Li