From 93120f3501cc9603bfbaf87dea815feb77b782b3 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 16 Jul 2006 20:17:04 +0000 Subject: [PATCH] In a Windows backend, don't build src/port/pgsleep.c's version of pg_usleep at all. Instead call the replacement function in port/win32/signal.c by that name. Avoids tricky macro-redefinition logic and suppresses a compiler warning; furthermore it ensures that no one can accidentally use the non-signal-aware version of pg_usleep in a Windows backend. --- src/backend/port/win32/signal.c | 16 ++++++++++++---- src/backend/postmaster/syslogger.c | 4 ++-- src/include/port/win32.h | 7 +------ src/port/pgsleep.c | 13 +++++++++---- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/backend/port/win32/signal.c b/src/backend/port/win32/signal.c index 06b45c8eb9..d12e29990f 100644 --- a/src/backend/port/win32/signal.c +++ b/src/backend/port/win32/signal.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/port/win32/signal.c,v 1.16 2006/03/05 15:58:35 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/port/win32/signal.c,v 1.17 2006/07/16 20:17:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,11 +41,19 @@ static pqsigfunc pg_signal_defaults[PG_SIGNAL_COUNT]; static DWORD WINAPI pg_signal_thread(LPVOID param); static BOOL WINAPI pg_console_handler(DWORD dwCtrlType); -/* Sleep function that can be interrupted by signals */ + +/* + * pg_usleep --- delay the specified number of microseconds, but + * stop waiting if a signal arrives. + * + * This replaces the non-signal-aware version provided by src/port/pgsleep.c. + */ void -pgwin32_backend_usleep(long microsec) +pg_usleep(long microsec) { - if (WaitForSingleObject(pgwin32_signal_event, (microsec < 500 ? 1 : (microsec + 500) / 1000)) == WAIT_OBJECT_0) + if (WaitForSingleObject(pgwin32_signal_event, + (microsec < 500 ? 1 : (microsec + 500) / 1000)) + == WAIT_OBJECT_0) { pgwin32_dispatch_queued_signals(); errno = EINTR; diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index 1fff118e44..23ff158fc6 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -18,7 +18,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.27 2006/07/11 18:26:10 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.28 2006/07/16 20:17:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -348,7 +348,7 @@ SysLoggerMain(int argc, char *argv[]) * detect pipe EOF. The main thread just wakes up once a second to * check for SIGHUP and rotation conditions. */ - pgwin32_backend_usleep(1000000); + pg_usleep(1000000L); #endif /* WIN32 */ if (pipe_eof_seen) diff --git a/src/include/port/win32.h b/src/include/port/win32.h index 60ac755a15..7a9180ea9c 100644 --- a/src/include/port/win32.h +++ b/src/include/port/win32.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.52 2006/06/07 22:24:45 momjian Exp $ */ +/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.53 2006/07/16 20:17:04 tgl Exp $ */ /* undefine and redefine after #include */ #undef mkdir @@ -221,11 +221,6 @@ HANDLE pgwin32_create_signal_listener(pid_t pid); void pgwin32_dispatch_queued_signals(void); void pg_queue_signal(int signum); -#ifndef FRONTEND -#define pg_usleep(t) pgwin32_backend_usleep(t) -void pgwin32_backend_usleep(long microsec); -#endif - /* In backend/port/win32/socket.c */ #ifndef FRONTEND #define socket(af, type, protocol) pgwin32_socket(af, type, protocol) diff --git a/src/port/pgsleep.c b/src/port/pgsleep.c index d39292880d..b003d3494d 100644 --- a/src/port/pgsleep.c +++ b/src/port/pgsleep.c @@ -6,7 +6,7 @@ * * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/port/pgsleep.c,v 1.7 2006/03/05 15:59:10 momjian Exp $ + * $PostgreSQL: pgsql/src/port/pgsleep.c,v 1.8 2006/07/16 20:17:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -15,6 +15,12 @@ #include #include +/* + * In a Windows backend, we don't use this implementation, but rather + * the signal-aware version in src/backend/port/win32/signal.c. + */ +#if defined(FRONTEND) || !defined(WIN32) + /* * pg_usleep --- delay the specified number of microseconds. * @@ -24,9 +30,6 @@ * * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds. */ -#ifdef pg_usleep -#undef pg_usleep -#endif void pg_usleep(long microsec) { @@ -43,3 +46,5 @@ pg_usleep(long microsec) #endif } } + +#endif /* defined(FRONTEND) || !defined(WIN32) */