1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +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

@@ -162,7 +162,7 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
int syncRepState;
/* Must reset the latch before testing state. */
ResetLatch(&MyProc->procLatch);
ResetLatch(MyLatch);
/*
* Try checking the state without the lock first. There's no
@@ -235,7 +235,7 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
* Wait on latch. Any condition that should wake us up will set the
* latch, so no need for timeout.
*/
WaitLatch(&MyProc->procLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, -1);
WaitLatch(MyLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, -1);
}
/*