aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/syslogger.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/syslogger.c
parent85a2a8903f7e9151793308d0638621003aded5ae (diff)
downloadpostgresql-59f71a0d0b56b2df48db4bf1738aece5551f7a47.tar.gz
postgresql-59f71a0d0b56b2df48db4bf1738aece5551f7a47.zip
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/syslogger.c')
-rw-r--r--src/backend/postmaster/syslogger.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index d127fb57711..41b8dbb6c25 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -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;
}