… | |
… | |
64 | # if HAVE_CLOCK_GETTIME |
64 | # if HAVE_CLOCK_GETTIME |
65 | # ifndef EV_USE_MONOTONIC |
65 | # ifndef EV_USE_MONOTONIC |
66 | # define EV_USE_MONOTONIC 1 |
66 | # define EV_USE_MONOTONIC 1 |
67 | # endif |
67 | # endif |
68 | # ifndef EV_USE_REALTIME |
68 | # ifndef EV_USE_REALTIME |
69 | # define EV_USE_REALTIME 1 |
69 | # define EV_USE_REALTIME 0 |
70 | # endif |
70 | # endif |
71 | # else |
71 | # else |
72 | # ifndef EV_USE_MONOTONIC |
72 | # ifndef EV_USE_MONOTONIC |
73 | # define EV_USE_MONOTONIC 0 |
73 | # define EV_USE_MONOTONIC 0 |
74 | # endif |
74 | # endif |
… | |
… | |
193 | # define EV_USE_MONOTONIC 0 |
193 | # define EV_USE_MONOTONIC 0 |
194 | # endif |
194 | # endif |
195 | #endif |
195 | #endif |
196 | |
196 | |
197 | #ifndef EV_USE_REALTIME |
197 | #ifndef EV_USE_REALTIME |
198 | # define EV_USE_REALTIME 0 |
198 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
199 | #endif |
199 | #endif |
200 | |
200 | |
201 | #ifndef EV_USE_NANOSLEEP |
201 | #ifndef EV_USE_NANOSLEEP |
202 | # if _POSIX_C_SOURCE >= 199309L |
202 | # if _POSIX_C_SOURCE >= 199309L |
203 | # define EV_USE_NANOSLEEP 1 |
203 | # define EV_USE_NANOSLEEP 1 |
… | |
… | |
397 | typedef ev_watcher_time *WT; |
397 | typedef ev_watcher_time *WT; |
398 | |
398 | |
399 | #define ev_active(w) ((W)(w))->active |
399 | #define ev_active(w) ((W)(w))->active |
400 | #define ev_at(w) ((WT)(w))->at |
400 | #define ev_at(w) ((WT)(w))->at |
401 | |
401 | |
402 | #if EV_USE_MONOTONIC |
402 | #if EV_USE_REALTIME |
403 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
403 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
404 | /* giving it a reasonably high chance of working on typical architetcures */ |
404 | /* giving it a reasonably high chance of working on typical architetcures */ |
|
|
405 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
|
|
406 | #endif |
|
|
407 | |
|
|
408 | #if EV_USE_MONOTONIC |
405 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
409 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
406 | #endif |
410 | #endif |
407 | |
411 | |
408 | #ifdef _WIN32 |
412 | #ifdef _WIN32 |
409 | # include "ev_win32.c" |
413 | # include "ev_win32.c" |
… | |
… | |
553 | |
557 | |
554 | ev_tstamp |
558 | ev_tstamp |
555 | ev_time (void) |
559 | ev_time (void) |
556 | { |
560 | { |
557 | #if EV_USE_REALTIME |
561 | #if EV_USE_REALTIME |
|
|
562 | if (expect_true (have_realtime)) |
|
|
563 | { |
558 | struct timespec ts; |
564 | struct timespec ts; |
559 | clock_gettime (CLOCK_REALTIME, &ts); |
565 | clock_gettime (CLOCK_REALTIME, &ts); |
560 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
566 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
561 | #else |
567 | } |
|
|
568 | #endif |
|
|
569 | |
562 | struct timeval tv; |
570 | struct timeval tv; |
563 | gettimeofday (&tv, 0); |
571 | gettimeofday (&tv, 0); |
564 | return tv.tv_sec + tv.tv_usec * 1e-6; |
572 | return tv.tv_sec + tv.tv_usec * 1e-6; |
565 | #endif |
|
|
566 | } |
573 | } |
567 | |
574 | |
568 | ev_tstamp inline_size |
575 | ev_tstamp inline_size |
569 | get_clock (void) |
576 | get_clock (void) |
570 | { |
577 | { |
… | |
… | |
1319 | static void noinline |
1326 | static void noinline |
1320 | loop_init (EV_P_ unsigned int flags) |
1327 | loop_init (EV_P_ unsigned int flags) |
1321 | { |
1328 | { |
1322 | if (!backend) |
1329 | if (!backend) |
1323 | { |
1330 | { |
|
|
1331 | #if EV_USE_REALTIME |
|
|
1332 | if (!have_realtime) |
|
|
1333 | { |
|
|
1334 | struct timespec ts; |
|
|
1335 | |
|
|
1336 | if (!clock_gettime (CLOCK_REALTIME, &ts)) |
|
|
1337 | have_realtime = 1; |
|
|
1338 | } |
|
|
1339 | #endif |
|
|
1340 | |
1324 | #if EV_USE_MONOTONIC |
1341 | #if EV_USE_MONOTONIC |
|
|
1342 | if (!have_monotonic) |
1325 | { |
1343 | { |
1326 | struct timespec ts; |
1344 | struct timespec ts; |
|
|
1345 | |
1327 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1346 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1328 | have_monotonic = 1; |
1347 | have_monotonic = 1; |
1329 | } |
1348 | } |
1330 | #endif |
1349 | #endif |
1331 | |
1350 | |
1332 | ev_rt_now = ev_time (); |
1351 | ev_rt_now = ev_time (); |
1333 | mn_now = get_clock (); |
1352 | mn_now = get_clock (); |
1334 | now_floor = mn_now; |
1353 | now_floor = mn_now; |