From ab9ed9be2378f02edf613e0543a29287e7484338 Mon Sep 17 00:00:00 2001 From: Noah Misch Date: Wed, 3 Apr 2019 17:11:16 -0700 Subject: [PATCH] Assert that pgwin32_signal_initialize() has been called early enough. Before the pgwin32_signal_initialize() call, the backend version of pg_usleep() has no effect. No in-tree code falls afoul of that today, but temporary commit 23078689a9921968ac0873b017be6e7f772f10bc did so. Discussion: https://postgr.es/m/20190402135442.GA1173872@rfd.leadboat.com --- src/backend/port/win32/signal.c | 3 +++ src/port/open.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/backend/port/win32/signal.c b/src/backend/port/win32/signal.c index dd91fe51f0..7d8961f4a4 100644 --- a/src/backend/port/win32/signal.c +++ b/src/backend/port/win32/signal.c @@ -52,6 +52,7 @@ static BOOL WINAPI pg_console_handler(DWORD dwCtrlType); void pg_usleep(long microsec) { + Assert(pgwin32_signal_event != NULL); if (WaitForSingleObject(pgwin32_signal_event, (microsec < 500 ? 1 : (microsec + 500) / 1000)) == WAIT_OBJECT_0) @@ -108,6 +109,7 @@ pgwin32_dispatch_queued_signals(void) { int exec_mask; + Assert(pgwin32_signal_event != NULL); EnterCriticalSection(&pg_signal_crit_sec); while ((exec_mask = UNBLOCKED_SIGNAL_QUEUE()) != 0) { @@ -209,6 +211,7 @@ pgwin32_create_signal_listener(pid_t pid) void pg_queue_signal(int signum) { + Assert(pgwin32_signal_event != NULL); if (signum >= PG_SIGNAL_COUNT || signum <= 0) return; diff --git a/src/port/open.c b/src/port/open.c index 436cbae482..f37afc7512 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -70,6 +70,9 @@ pgwin32_open(const char *fileName, int fileFlags,...) (O_RANDOM | O_SEQUENTIAL | O_TEMPORARY) | _O_SHORT_LIVED | O_DSYNC | O_DIRECT | (O_CREAT | O_TRUNC | O_EXCL) | (O_TEXT | O_BINARY))) == fileFlags); +#ifndef FRONTEND + Assert(pgwin32_signal_event != NULL); /* small chance of pg_usleep() */ +#endif #ifdef FRONTEND -- 2.40.0