1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +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

@ -85,7 +85,6 @@ static FILE *csvlogFile = NULL;
NON_EXEC_STATIC pg_time_t first_syslogger_file_time = 0;
static char *last_file_name = NULL;
static char *last_csv_file_name = NULL;
static Latch sysLoggerLatch;
/*
* Buffers for saving partial messages from different backends.
@ -231,12 +230,6 @@ SysLoggerMain(int argc, char *argv[])
syslogPipe[1] = 0;
#endif
InitializeLatchSupport(); /* needed for latch waits */
/* Initialize private latch for use by signal handlers */
InitLatch(&sysLoggerLatch);
/*
* Properly accept or ignore signals the postmaster might send us
*
@ -302,7 +295,7 @@ SysLoggerMain(int argc, char *argv[])
#endif
/* Clear any already-pending wakeups */
ResetLatch(&sysLoggerLatch);
ResetLatch(MyLatch);
/*
* Process any requests or signals received recently.
@ -428,7 +421,7 @@ SysLoggerMain(int argc, char *argv[])
* Sleep until there's something to do
*/
#ifndef WIN32
rc = WaitLatchOrSocket(&sysLoggerLatch,
rc = WaitLatchOrSocket(MyLatch,
WL_LATCH_SET | WL_SOCKET_READABLE | cur_flags,
syslogPipe[0],
cur_timeout);
@ -480,7 +473,7 @@ SysLoggerMain(int argc, char *argv[])
*/
LeaveCriticalSection(&sysloggerSection);
(void) WaitLatch(&sysLoggerLatch,
(void) WaitLatch(MyLatch,
WL_LATCH_SET | cur_flags,
cur_timeout);
@ -1061,7 +1054,7 @@ pipeThread(void *arg)
{
if (ftell(syslogFile) >= Log_RotationSize * 1024L ||
(csvlogFile != NULL && ftell(csvlogFile) >= Log_RotationSize * 1024L))
SetLatch(&sysLoggerLatch);
SetLatch(MyLatch);
}
LeaveCriticalSection(&sysloggerSection);
}
@ -1073,7 +1066,7 @@ pipeThread(void *arg)
flush_pipe_input(logbuffer, &bytes_in_logbuffer);
/* set the latch to waken the main thread, which will quit */
SetLatch(&sysLoggerLatch);
SetLatch(MyLatch);
LeaveCriticalSection(&sysloggerSection);
_endthread();
@ -1353,7 +1346,7 @@ sigHupHandler(SIGNAL_ARGS)
int save_errno = errno;
got_SIGHUP = true;
SetLatch(&sysLoggerLatch);
SetLatch(MyLatch);
errno = save_errno;
}
@ -1365,7 +1358,7 @@ sigUsr1Handler(SIGNAL_ARGS)
int save_errno = errno;
rotation_requested = true;
SetLatch(&sysLoggerLatch);
SetLatch(MyLatch);
errno = save_errno;
}