Add a default local latch for use in signal handlers.
authorAndres Freund <[email protected]>
Wed, 14 Jan 2015 17:45:22 +0000 (18:45 +0100)
committerAndres Freund <[email protected]>
Wed, 14 Jan 2015 17:45:22 +0000 (18:45 +0100)
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[email protected]

23 files changed:
src/backend/postmaster/autovacuum.c
src/backend/postmaster/bgworker.c
src/backend/postmaster/bgwriter.c
src/backend/postmaster/checkpointer.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/syslogger.c
src/backend/postmaster/walwriter.c
src/backend/replication/syncrep.c
src/backend/storage/ipc/procsignal.c
src/backend/storage/ipc/shm_mq.c
src/backend/storage/lmgr/proc.c
src/backend/tcop/postgres.c
src/backend/utils/adt/misc.c
src/backend/utils/init/globals.c
src/backend/utils/init/miscinit.c
src/backend/utils/misc/timeout.c
src/include/miscadmin.h
src/include/storage/latch.h
src/test/modules/test_shm_mq/setup.c
src/test/modules/test_shm_mq/test.c
src/test/modules/test_shm_mq/worker.c
src/test/modules/worker_spi/worker_spi.c

index a26eee25d46405515ea7944b2ce95290893969b1..02f871ce22b24cdf80af81584b07aa42b04cb8ff 100644 (file)
@@ -589,11 +589,11 @@ AutoVacLauncherMain(int argc, char *argv[])
         * Wait until naptime expires or we get some type of signal (all the
         * signal handlers will wake us by calling SetLatch).
         */
-       rc = WaitLatch(&MyProc->procLatch,
+       rc = WaitLatch(MyLatch,
                       WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
                       (nap.tv_sec * 1000L) + (nap.tv_usec / 1000L));
 
-       ResetLatch(&MyProc->procLatch);
+       ResetLatch(MyLatch);
 
        DisableCatchupInterrupt();
 
@@ -1341,8 +1341,7 @@ avl_sighup_handler(SIGNAL_ARGS)
    int         save_errno = errno;
 
    got_SIGHUP = true;
-   if (MyProc)
-       SetLatch(&MyProc->procLatch);
+   SetLatch(MyLatch);
 
    errno = save_errno;
 }
@@ -1354,8 +1353,7 @@ avl_sigusr2_handler(SIGNAL_ARGS)
    int         save_errno = errno;
 
    got_SIGUSR2 = true;
-   if (MyProc)
-       SetLatch(&MyProc->procLatch);
+   SetLatch(MyLatch);
 
    errno = save_errno;
 }
@@ -1367,8 +1365,7 @@ avl_sigterm_handler(SIGNAL_ARGS)
    int         save_errno = errno;
 
    got_SIGTERM = true;
-   if (MyProc)
-       SetLatch(&MyProc->procLatch);
+   SetLatch(MyLatch);
 
    errno = save_errno;
 }