Skip to content

Commit 43aa96c

Browse files
ashutosh-bapatCommitfest Bot
authored andcommitted
PGReserveSemaphores() called from CreateSharedMemoryAndSemaphores()
Before e256266, PGReserveSemaphores() was required to be called before SpinlockSemaInit() since spinlocks may be implemented using semaphores on some platforms. SpinlockSemaInit() was required to be called before InitShmemAllocation() since the latter initialized a spinlock to synchronize shared memory allocations. e256266 removed the call to SpinlockSemaInit() from CreateSharedMemoryAndSemaphores() but left the call to PGReserveSemaphores() in CreateSharedMemoryAndSemaphores(), even though it fits in CreateOrAttachShmemStructs() along with the calls to other functions allocating shared memory structures. Add a comment explaining this absurdity. To be backpatched to PG 18. Author: Ashutosh Bapat <[email protected]> Discussion: https://www.postgresql.org/message-id/CAExHW5seSZpPx-znjidVZNzdagGHOk06F+Ds88MpPUbxd1kTaA@mail.gmail.com
1 parent 2fc3107 commit 43aa96c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/storage/ipc/ipci.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ CreateSharedMemoryAndSemaphores(void)
225225
InitShmemAccess(seghdr);
226226

227227
/*
228-
* Create semaphores
228+
* Create semaphores. This is done here because of a now-non-existent
229+
* dependency between spinlocks, which were required for shared memory
230+
* allocation, and semaphores, which were allocated in the shared memory
231+
* on some platforms. Ideally it should be done in
232+
* CreateOrAttachShmemStructs() where we allocate other shared memory
233+
* structures.
229234
*/
230235
PGReserveSemaphores(numSemas);
231236

0 commit comments

Comments
 (0)