Skip to content

Commit 7ae2db1

Browse files
committed
Try to get pg_test_thread to compile on Windows by using a sleeper
thread.
1 parent 58d7462 commit 7ae2db1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

contrib/pg_test_fsync/pg_test_fsync.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,26 @@
2828
#define OPS_FORMAT "%9.3f ops/sec"
2929

3030
/* These are macros to avoid timing the function call overhead. */
31+
#ifndef WIN32
3132
#define START_TIMER \
3233
do { \
3334
alarm_triggered = false; \
3435
alarm(secs_per_test); \
3536
gettimeofday(&start_t, NULL); \
3637
} while (0)
38+
#else
39+
#define START_TIMER \
40+
do { \
41+
alarm_triggered = false; \
42+
if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == \
43+
INVALID_HANDLE_VALUE) \
44+
{ \
45+
fprintf(stderr, "Cannot create thread for alarm\n"); \
46+
exit(1); \
47+
} \
48+
gettimeofday(&start_t, NULL); \
49+
} while (0)
50+
#endif
3751

3852
#define STOP_TIMER \
3953
do { \
@@ -82,7 +96,9 @@ main(int argc, char *argv[])
8296
/* Prevent leaving behind the test file */
8397
signal(SIGINT, signal_cleanup);
8498
signal(SIGTERM, signal_cleanup);
99+
#ifndef WIN32
85100
signal(SIGALRM, process_alarm);
101+
#endif
86102
#ifdef SIGHUP
87103
/* Not defined on win32 */
88104
signal(SIGHUP, signal_cleanup);
@@ -553,7 +569,13 @@ print_elapse(struct timeval start_t, struct timeval stop_t, int ops)
553569
static void
554570
process_alarm(int sig)
555571
{
572+
#ifdef WIN32
573+
sleep(secs_per_test);
574+
#endif
556575
alarm_triggered = true;
576+
#ifdef WIN32
577+
ExitThread(0);
578+
#endif
557579
}
558580

559581
static void

0 commit comments

Comments
 (0)