From 388c2f93254b90921e207bc1cf52e1c8e0f4bba8 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Wed, 15 Feb 2012 07:10:48 -0500
Subject: [PATCH] Fix pg_test_fsync Win32 problems reported by the build farm; 
 add comments about the alarm method used on Win32.

---
 contrib/pg_test_fsync/pg_test_fsync.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/contrib/pg_test_fsync/pg_test_fsync.c b/contrib/pg_test_fsync/pg_test_fsync.c
index c2867f5892d..7f92bc88182 100644
--- a/contrib/pg_test_fsync/pg_test_fsync.c
+++ b/contrib/pg_test_fsync/pg_test_fsync.c
@@ -36,6 +36,7 @@ do { \
 	gettimeofday(&start_t, NULL); \
 } while (0)
 #else
+/* WIN32 doesn't support alarm, so we create a thread and sleep there */
 #define START_TIMER	\
 do { \
 	alarm_triggered = false; \
@@ -76,7 +77,11 @@ static void test_sync(int writes_per_op);
 static void test_open_syncs(void);
 static void test_open_sync(const char *msg, int writes_size);
 static void test_file_descriptor_sync(void);
+#ifndef WIN32
 static void process_alarm(int sig);
+#else
+static DWORD WINAPI process_alarm(LPVOID param);
+#endif
 static void signal_cleanup(int sig);
 
 #ifdef HAVE_FSYNC_WRITETHROUGH
@@ -566,17 +571,22 @@ print_elapse(struct timeval start_t, struct timeval stop_t, int ops)
 	printf(OPS_FORMAT "\n", per_second);
 }
 
+#ifndef WIN32
 static void
 process_alarm(int sig)
 {
-#ifdef WIN32
-	sleep(secs_per_test);
-#endif
 	alarm_triggered = true;
-#ifdef WIN32
+}
+#else
+static DWORD WINAPI
+process_alarm(LPVOID param)
+{
+	/* WIN32 doesn't support alarm, so we create a thread and sleep here */
+	Sleep(secs_per_test * 1000);
+	alarm_triggered = true;
 	ExitThread(0);
-#endif
 }
+#endif
 
 static void
 die(const char *str)
-- 
GitLab