diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-10-08 15:06:34 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-10-08 15:06:34 +0300 |
commit | 2bbc261ddbdfee2def5d14ee9fcc09c70bdf84e6 (patch) | |
tree | e163ad3a84702214f2bd678de341b15e612246e4 /src/backend/storage/ipc | |
parent | 85ec945b7880931cb506392101cb0b00209b78ba (diff) |
Use an shmem_exit callback to remove backend from PMChildFlags on exit
This seems nicer than having to duplicate the logic between
InitProcess() and ProcKill() for which child processes have a
PMChildFlags slot.
Move the MarkPostmasterChildActive() call earlier in InitProcess(),
out of the section protected by the spinlock.
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/a102f15f-eac4-4ff2-af02-f9ff209ec66f@iki.fi
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r-- | src/backend/storage/ipc/pmsignal.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index 27844b46a2b..c801e9bec51 100644 --- a/src/backend/storage/ipc/pmsignal.c +++ b/src/backend/storage/ipc/pmsignal.c @@ -24,6 +24,7 @@ #include "miscadmin.h" #include "postmaster/postmaster.h" #include "replication/walsender.h" +#include "storage/ipc.h" #include "storage/pmsignal.h" #include "storage/shmem.h" #include "utils/memutils.h" @@ -121,6 +122,8 @@ postmaster_death_handler(SIGNAL_ARGS) #endif /* USE_POSTMASTER_DEATH_SIGNAL */ +static void MarkPostmasterChildInactive(int code, Datum arg); + /* * PMSignalShmemSize * Compute space needed for pmsignal.c's shared memory @@ -316,11 +319,14 @@ IsPostmasterChildWalSender(int slot) } /* - * MarkPostmasterChildActive - mark a postmaster child as about to begin + * RegisterPostmasterChildActive - mark a postmaster child as about to begin * actively using shared memory. This is called in the child process. + * + * This register an shmem exit hook to mark us as inactive again when the + * process exits normally. */ void -MarkPostmasterChildActive(void) +RegisterPostmasterChildActive(void) { int slot = MyPMChildSlot; @@ -328,6 +334,9 @@ MarkPostmasterChildActive(void) slot--; Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ASSIGNED); PMSignalState->PMChildFlags[slot] = PM_CHILD_ACTIVE; + + /* Arrange to clean up at exit. */ + on_shmem_exit(MarkPostmasterChildInactive, 0); } /* @@ -352,8 +361,8 @@ MarkPostmasterChildWalSender(void) * MarkPostmasterChildInactive - mark a postmaster child as done using * shared memory. This is called in the child process. */ -void -MarkPostmasterChildInactive(void) +static void +MarkPostmasterChildInactive(int code, Datum arg) { int slot = MyPMChildSlot; |