From: Nathan Bossart Date: Thu, 9 Jul 2026 16:09:53 +0000 (-0500) Subject: Remove WaitEventCustomCounterData. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8f7af125e03739b66998a75840dedd943ec3624e;p=thirdparty%2Fpostgresql.git Remove WaitEventCustomCounterData. 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 Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/ak8MeTS9QBmz6DKt%40nathan --- diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c index 95635c7f56c..e36a740a888 100644 --- a/src/backend/utils/activity/wait_event.c +++ b/src/backend/utils/activity/wait_event.c @@ -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; diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index f6e87d04b0e..56c1f997f88 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -3421,7 +3421,6 @@ WaitEvent WaitEventActivity WaitEventBuffer WaitEventClient -WaitEventCustomCounterData WaitEventCustomEntryByInfo WaitEventCustomEntryByName WaitEventIO