From: Bruce Momjian Date: Wed, 15 Feb 2012 02:53:17 +0000 (-0500) Subject: Try to get pg_test_thread to compile on Windows by using a sleeper X-Git-Tag: REL9_2_BETA1~421 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ae2db1d1e7bc95ef8cee380d549dd03a2f8ce88;p=postgresql Try to get pg_test_thread to compile on Windows by using a sleeper thread. --- diff --git a/contrib/pg_test_fsync/pg_test_fsync.c b/contrib/pg_test_fsync/pg_test_fsync.c index 02a9e2112f..c2867f5892 100644 --- a/contrib/pg_test_fsync/pg_test_fsync.c +++ b/contrib/pg_test_fsync/pg_test_fsync.c @@ -28,12 +28,26 @@ #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