]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove WaitEventCustomCounterData.
authorNathan Bossart <nathan@postgresql.org>
Thu, 9 Jul 2026 16:09:53 +0000 (11:09 -0500)
committerNathan Bossart <nathan@postgresql.org>
Thu, 9 Jul 2026 16:09:53 +0000 (11:09 -0500)
The spinlock is unnecessary because the counter is only ever
accessed with WaitEventCustomLock held exclusively.  This commit
removes the struct definition and converts WaitEventCustomCounter
to a pointer to an integer in shared memory.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/ak8MeTS9QBmz6DKt%40nathan

src/backend/utils/activity/wait_event.c
src/tools/pgindent/typedefs.list

index 95635c7f56ce726ca34d91025307b0558e1bd943..e36a740a888d96378236efd2546e449a76d565c3 100644 (file)
@@ -26,7 +26,6 @@
 #include "storage/lwlock.h"
 #include "storage/shmem.h"
 #include "storage/subsystems.h"
-#include "storage/spin.h"
 #include "utils/wait_event.h"
 
 
@@ -81,14 +80,7 @@ typedef struct WaitEventCustomEntryByName
 
 
 /* dynamic allocation counter for custom wait events */
-typedef struct WaitEventCustomCounterData
-{
-       int                     nextId;                 /* next ID to assign */
-       slock_t         mutex;                  /* protects the counter */
-} WaitEventCustomCounterData;
-
-/* pointer to the shared memory */
-static WaitEventCustomCounterData *WaitEventCustomCounter;
+static int *WaitEventCustomCounter;
 
 /* first event ID of custom wait events */
 #define WAIT_EVENT_CUSTOM_INITIAL_ID   1
@@ -110,8 +102,8 @@ const ShmemCallbacks WaitEventCustomShmemCallbacks = {
 static void
 WaitEventCustomShmemRequest(void *arg)
 {
-       ShmemRequestStruct(.name = "WaitEventCustomCounterData",
-                                          .size = sizeof(WaitEventCustomCounterData),
+       ShmemRequestStruct(.name = "WaitEventCustomCounter",
+                                          .size = sizeof(int),
                                           .ptr = (void **) &WaitEventCustomCounter,
                );
        ShmemRequestHash(.name = "WaitEventCustom hash by wait event information",
@@ -134,9 +126,8 @@ WaitEventCustomShmemRequest(void *arg)
 static void
 WaitEventCustomShmemInit(void *arg)
 {
-       /* initialize the allocation counter and its spinlock. */
-       WaitEventCustomCounter->nextId = WAIT_EVENT_CUSTOM_INITIAL_ID;
-       SpinLockInit(&WaitEventCustomCounter->mutex);
+       /* initialize the allocation counter */
+       *WaitEventCustomCounter = WAIT_EVENT_CUSTOM_INITIAL_ID;
 }
 
 /*
@@ -221,19 +212,12 @@ WaitEventCustomNew(uint32 classId, const char *wait_event_name)
        }
 
        /* Allocate a new event Id */
-       SpinLockAcquire(&WaitEventCustomCounter->mutex);
-
-       if (WaitEventCustomCounter->nextId >= WAIT_EVENT_CUSTOM_HASH_SIZE)
-       {
-               SpinLockRelease(&WaitEventCustomCounter->mutex);
+       if (*WaitEventCustomCounter >= WAIT_EVENT_CUSTOM_HASH_SIZE)
                ereport(ERROR,
                                errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
                                errmsg("too many custom wait events"));
-       }
-
-       eventId = WaitEventCustomCounter->nextId++;
 
-       SpinLockRelease(&WaitEventCustomCounter->mutex);
+       eventId = (*WaitEventCustomCounter)++;
 
        /* Register the new wait event */
        wait_event_info = classId | eventId;
index f6e87d04b0ed9b41fd17e49dbce73f899d28f493..56c1f997f88b1002fd03a1bcdd74bb42314d4182 100644 (file)
@@ -3421,7 +3421,6 @@ WaitEvent
 WaitEventActivity
 WaitEventBuffer
 WaitEventClient
-WaitEventCustomCounterData
 WaitEventCustomEntryByInfo
 WaitEventCustomEntryByName
 WaitEventIO