summaryrefslogtreecommitdiff
path: root/src/backend/postmaster/pgarch.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2015-01-14 18:45:22 +0100
committerAndres Freund <andres@anarazel.de>2015-01-14 18:45:22 +0100
commit59f71a0d0b56b2df48db4bf1738aece5551f7a47 (patch)
tree6023eb572eade66adb21ee0ae84fd6aa33e30ac9 /src/backend/postmaster/pgarch.c
parent85a2a8903f7e9151793308d0638621003aded5ae (diff)
downloadpostgresql-59f71a0d0b56b2df48db4bf1738aece5551f7a47.tar.gz
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
Diffstat (limited to 'src/backend/postmaster/pgarch.c')
-rw-r--r--src/backend/postmaster/pgarch.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 78dec3a4c6..9b689af915 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -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)