@@ -121,6 +121,19 @@ _dispatch_get_nanoseconds(void)
121
121
#endif
122
122
}
123
123
124
+ /* On the use of clock sources in the CLOCK_MONOTONIC family
125
+ *
126
+ * The code below requires monotonic clock sources that only tick
127
+ * while the machine is running.
128
+ *
129
+ * Per POSIX, the CLOCK_MONOTONIC family is supposed to tick during
130
+ * machine sleep; this is not the case on Linux, and that behavior
131
+ * became part of the Linux ABI.
132
+ *
133
+ * Using the CLOCK_MONOTONIC family on POSIX-compliant platforms
134
+ * will lead to bugs, hence its use is restricted to Linux.
135
+ */
136
+
124
137
static inline uint64_t
125
138
_dispatch_absolute_time (void )
126
139
{
@@ -130,7 +143,7 @@ _dispatch_absolute_time(void)
130
143
struct timespec ts ;
131
144
dispatch_assume_zero (clock_gettime (CLOCK_UPTIME , & ts ));
132
145
return _dispatch_timespec_to_nano (ts );
133
- #elif HAVE_DECL_CLOCK_MONOTONIC
146
+ #elif HAVE_DECL_CLOCK_MONOTONIC && defined( __linux__ )
134
147
struct timespec ts ;
135
148
dispatch_assume_zero (clock_gettime (CLOCK_MONOTONIC , & ts ));
136
149
return _dispatch_timespec_to_nano (ts );
@@ -152,7 +165,7 @@ _dispatch_approximate_time(void)
152
165
struct timespec ts ;
153
166
dispatch_assume_zero (clock_gettime (CLOCK_UPTIME_FAST , & ts ));
154
167
return _dispatch_timespec_to_nano (ts );
155
- #elif HAVE_DECL_CLOCK_MONOTONIC_COARSE
168
+ #elif HAVE_DECL_CLOCK_MONOTONIC_COARSE && defined( __linux__ )
156
169
struct timespec ts ;
157
170
dispatch_assume_zero (clock_gettime (CLOCK_MONOTONIC_COARSE , & ts ));
158
171
return _dispatch_timespec_to_nano (ts );
0 commit comments