Skip to content

Commit ec41b1e

Browse files
committed
Fix for old mingw without clock_gettime and clock_getres
1 parent 0564973 commit ec41b1e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

include/ruby/win32.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,26 @@ typedef unsigned int uintptr_t;
127127

128128
typedef int clockid_t;
129129
#if defined(__MINGW32__)
130+
/* I don't know why but these return some strange values. */
130131
#undef CLOCK_PROCESS_CPUTIME_ID
131132
#undef CLOCK_THREAD_CPUTIME_ID
132133
#undef CLOCK_REALTIME_COARSE
133134
#endif
134-
#if defined(HAVE_CLOCK_GETTIME) && !defined(CLOCK_REALTIME)
135-
#define CLOCK_REALTIME 0
136-
#define CLOCK_MONOTONIC 1
135+
136+
/* defined in win32/win32.c for old versions */
137+
#if !defined(__MINGW32__) || !defined(HAVE_CLOCK_GETTIME)
138+
# define HAVE_CLOCK_GETTIME 1
139+
# define NEED_CLOCK_GETTIME 1
140+
#endif
141+
#if !defined(__MINGW32__) || !defined(HAVE_CLOCK_GETRES)
142+
# define HAVE_CLOCK_GETRES 1
143+
# define NEED_CLOCK_GETRES 1
144+
#endif
145+
#ifndef CLOCK_REALTIME
146+
# define CLOCK_REALTIME 0
147+
#endif
148+
#ifndef CLOCK_MONOTONIC
149+
# define CLOCK_MONOTONIC 1
137150
#endif
138151

139152
#undef utime

win32/win32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4761,7 +4761,7 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
47614761
return 0;
47624762
}
47634763

4764-
#if !defined(__MINGW32__) || !defined(HAVE_CLOCK_GETTIME)
4764+
#ifdef NEED_CLOCK_GETTIME
47654765
/* License: Ruby's */
47664766
int
47674767
clock_gettime(clockid_t clock_id, struct timespec *sp)
@@ -4803,7 +4803,7 @@ clock_gettime(clockid_t clock_id, struct timespec *sp)
48034803
}
48044804
#endif
48054805

4806-
#if !defined(__MINGW32__) || !defined(HAVE_CLOCK_GETRES)
4806+
#ifdef NEED_CLOCK_GETRES
48074807
/* License: Ruby's */
48084808
int
48094809
clock_getres(clockid_t clock_id, struct timespec *sp)

0 commit comments

Comments
 (0)