1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add a default local latch for use in signal handlers.

To do so, move InitializeLatchSupport() into the new common process
initialization functions, and add a new global variable MyLatch.

MyLatch is usable as soon InitPostmasterChild() has been called
(i.e. very early during startup). Initially it points to a process
local latch that exists in all processes. InitProcess/InitAuxiliaryProcess
then replaces that local latch with PGPROC->procLatch. During shutdown
the reverse happens.

This is primarily advantageous for two reasons: For one it simplifies
dealing with the shared process latch, especially in signal handlers,
because instead of having to check for MyProc, MyLatch can be used
unconditionally. For another, a later patch that makes FEs/BE
communication use latches, now can rely on the existence of a latch,
even before having gone through InitProcess.

Discussion: 20140927191243.GD5423@alap3.anarazel.de
This commit is contained in:
Andres Freund
2015-01-14 18:45:22 +01:00
parent 85a2a8903f
commit 59f71a0d0b
23 changed files with 136 additions and 134 deletions

View File

@ -78,11 +78,6 @@ static volatile sig_atomic_t got_SIGTERM = false;
static volatile sig_atomic_t wakened = false;
static volatile sig_atomic_t ready_to_stop = false;
/*
* Latch used by signal handlers to wake up the sleep in the main loop.
*/
static Latch mainloop_latch;
/* ----------
* Local function forward declarations
* ----------
@ -220,10 +215,6 @@ pgarch_forkexec(void)
NON_EXEC_STATIC void
PgArchiverMain(int argc, char *argv[])
{
InitializeLatchSupport(); /* needed for latch waits */
InitLatch(&mainloop_latch); /* initialize latch used in main loop */
/*
* Ignore all signals usually bound to some action in the postmaster,
* except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
@ -269,7 +260,7 @@ ArchSigHupHandler(SIGNAL_ARGS)
/* set flag to re-read config file at next convenient time */
got_SIGHUP = true;
SetLatch(&mainloop_latch);
SetLatch(MyLatch);
errno = save_errno;
}
@ -287,7 +278,7 @@ ArchSigTermHandler(SIGNAL_ARGS)
* archive commands.
*/
got_SIGTERM = true;
SetLatch(&mainloop_latch);
SetLatch(MyLatch);
errno = save_errno;
}
@ -300,7 +291,7 @@ pgarch_waken(SIGNAL_ARGS)
/* set flag that there is work to be done */
wakened = true;
SetLatch(&mainloop_latch);
SetLatch(MyLatch);
errno = save_errno;
}
@ -313,7 +304,7 @@ pgarch_waken_stop(SIGNAL_ARGS)
/* set flag to do a final cycle and shut down afterwards */
ready_to_stop = true;
SetLatch(&mainloop_latch);
SetLatch(MyLatch);
errno = save_errno;
}
@ -344,7 +335,7 @@ pgarch_MainLoop(void)
*/
do
{
ResetLatch(&mainloop_latch);
ResetLatch(MyLatch);
/* When we get SIGUSR2, we do one more archive cycle, then exit */
time_to_stop = ready_to_stop;
@ -397,7 +388,7 @@ pgarch_MainLoop(void)
{
int rc;
rc = WaitLatch(&mainloop_latch,
rc = WaitLatch(MyLatch,
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
timeout * 1000L);
if (rc & WL_TIMEOUT)