]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use ShmemInitStruct to allocate shmem for semaphores
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 30 Mar 2026 20:39:35 +0000 (23:39 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 30 Mar 2026 20:39:35 +0000 (23:39 +0300)
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

src/backend/port/posix_sema.c
src/backend/port/sysv_sema.c

index e368e5ee7ed1af83617c05b4f386a53250140bac..40205b7d4004d7ec29e6157f1f7f47f89062f25d 100644 (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;
index 86c4d359ef741c8e18827a866e623bab8f6a5901..4b2bf84072f1360e3a3b039aab4541b4ef5d9b74 100644 (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;