mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +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:
@@ -252,7 +252,7 @@ WalWriterMain(void)
|
||||
}
|
||||
|
||||
/* Clear any already-pending wakeups */
|
||||
ResetLatch(&MyProc->procLatch);
|
||||
ResetLatch(MyLatch);
|
||||
|
||||
/*
|
||||
* Process any requests or signals received recently.
|
||||
@@ -287,7 +287,7 @@ WalWriterMain(void)
|
||||
else
|
||||
cur_timeout = WalWriterDelay * HIBERNATE_FACTOR;
|
||||
|
||||
rc = WaitLatch(&MyProc->procLatch,
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
cur_timeout);
|
||||
|
||||
@@ -345,8 +345,7 @@ WalSigHupHandler(SIGNAL_ARGS)
|
||||
int save_errno = errno;
|
||||
|
||||
got_SIGHUP = true;
|
||||
if (MyProc)
|
||||
SetLatch(&MyProc->procLatch);
|
||||
SetLatch(MyLatch);
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
@@ -358,8 +357,7 @@ WalShutdownHandler(SIGNAL_ARGS)
|
||||
int save_errno = errno;
|
||||
|
||||
shutdown_requested = true;
|
||||
if (MyProc)
|
||||
SetLatch(&MyProc->procLatch);
|
||||
SetLatch(MyLatch);
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user