File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -215,11 +215,25 @@ int main(int argc, char *argv[]) {
215
215
216
216
if (deadline.tv_sec > now.tv_sec ||
217
217
(deadline.tv_sec == now.tv_sec && deadline.tv_nsec > now.tv_nsec )) {
218
+ #if _POSIX_C_SOURCE >= 200112L
218
219
if (clock_nanosleep (CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline,
219
220
nullptr ) == -1 ) {
220
221
std::cerr << " clock_nanosleep: " << strerror (errno) << std::endl;
221
222
return 1 ;
222
223
}
224
+ #else
225
+ timespec duration;
226
+ duration.tv_sec = deadline.tv_sec - now.tv_sec ;
227
+ duration.tv_nsec = deadline.tv_nsec - now.tv_nsec ;
228
+ if (duration.tv_nsec < 0 ) {
229
+ --duration.tv_sec ;
230
+ duration.tv_nsec += 1000000000L ;
231
+ }
232
+ if (nanosleep (&duration, nullptr ) == -1 ) {
233
+ std::cerr << " nanosleep: " << strerror (errno) << std::endl;
234
+ return 1 ;
235
+ }
236
+ #endif
223
237
}
224
238
225
239
#ifdef __GLIBC__
You can’t perform that action at this time.
0 commit comments