]> granicus.if.org Git - postgresql/commitdiff
Try to get pg_test_thread to compile on Windows by using a sleeper
authorBruce Momjian <bruce@momjian.us>
Wed, 15 Feb 2012 02:53:17 +0000 (21:53 -0500)
committerBruce Momjian <bruce@momjian.us>
Wed, 15 Feb 2012 02:53:17 +0000 (21:53 -0500)
thread.

contrib/pg_test_fsync/pg_test_fsync.c

index 02a9e2112fdbcdd7ea56bfd645f262c9e2ca641e..c2867f5892dd008eab6838ab662538c61126e3a5 100644 (file)
 #define OPS_FORMAT                     "%9.3f ops/sec"
 
 /* These are macros to avoid timing the function call overhead. */
+#ifndef WIN32
 #define START_TIMER    \
 do { \
        alarm_triggered = false; \
        alarm(secs_per_test); \
        gettimeofday(&start_t, NULL); \
 } while (0)
+#else
+#define START_TIMER    \
+do { \
+       alarm_triggered = false; \
+       if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == \
+               INVALID_HANDLE_VALUE) \
+       { \
+               fprintf(stderr, "Cannot create thread for alarm\n"); \
+               exit(1); \
+       } \
+       gettimeofday(&start_t, NULL); \
+} while (0)
+#endif
 
 #define STOP_TIMER     \
 do { \
@@ -82,7 +96,9 @@ main(int argc, char *argv[])
        /* Prevent leaving behind the test file */
        signal(SIGINT, signal_cleanup);
        signal(SIGTERM, signal_cleanup);
+#ifndef WIN32
        signal(SIGALRM, process_alarm);
+#endif
 #ifdef SIGHUP
        /* Not defined on win32 */
        signal(SIGHUP, signal_cleanup);
@@ -553,7 +569,13 @@ print_elapse(struct timeval start_t, struct timeval stop_t, int ops)
 static void
 process_alarm(int sig)
 {
+#ifdef WIN32
+       sleep(secs_per_test);
+#endif
        alarm_triggered = true;
+#ifdef WIN32
+       ExitThread(0);
+#endif
 }
 
 static void