Use ShmemInitStruct to allocate shmem for semaphores

This makes them visible in pg_shmem_allocations

Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://www.postgresql.org/message-id/01ab1d41-3eda-4705-8bbd-af898f5007f1@iki.fi
This commit is contained in:
Heikki Linnakangas 2026-03-30 23:39:35 +03:00
parent 378a216187
commit 40c41dc773
2 changed files with 7 additions and 2 deletions

View file

@ -196,6 +196,7 @@ void
PGReserveSemaphores(int maxSemas)
{
struct stat statbuf;
bool found;
/*
* We use the data directory's inode number to seed the search for free
@ -216,7 +217,8 @@ PGReserveSemaphores(int maxSemas)
#else
sharedSemas = (PGSemaphore)
ShmemAlloc(PGSemaphoreShmemSize(maxSemas));
ShmemInitStruct("Semaphores", PGSemaphoreShmemSize(maxSemas), &found);
Assert(!found);
#endif
numSems = 0;

View file

@ -330,6 +330,7 @@ void
PGReserveSemaphores(int maxSemas)
{
struct stat statbuf;
bool found;
/*
* We use the data directory's inode number to seed the search for free
@ -344,7 +345,9 @@ PGReserveSemaphores(int maxSemas)
DataDir)));
sharedSemas = (PGSemaphore)
ShmemAlloc(PGSemaphoreShmemSize(maxSemas));
ShmemInitStruct("Semaphores", PGSemaphoreShmemSize(maxSemas), &found);
Assert(!found);
numSharedSemas = 0;
maxSharedSemas = maxSemas;