diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-03 09:53:11 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-03 09:53:11 +0900 |
| commit | 5e95f11756c13f730f9bc095f42a444f46f6b8b3 (patch) | |
| tree | 5c6af0b8e033e27689098e30143baea83650e42d /mrbgems/mruby-time/src/time.c | |
| parent | 0c631a4c08371f5c12d2a774e7ab49fd9a3dfbee (diff) | |
| download | mruby-5e95f11756c13f730f9bc095f42a444f46f6b8b3.tar.gz mruby-5e95f11756c13f730f9bc095f42a444f46f6b8b3.zip | |
time.c: use `clock_gettime()` if possible.
Diffstat (limited to 'mrbgems/mruby-time/src/time.c')
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 5093a73ce..50d618fc3 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -21,6 +21,7 @@ #endif #include <stdlib.h> +#include <unistd.h> #define NDIV(x,y) (-(-((x)+1)/(y))-1) #define TO_S_FMT "%Y-%m-%d %H:%M:%S " @@ -382,6 +383,13 @@ current_mrb_time(mrb_state *mrb) sec = ts.tv_sec; usec = ts.tv_nsec / 1000; } +#elif (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) + { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + sec = ts.tv_sec; + usec = ts.tv_nsec / 1000; + } #elif defined(NO_GETTIMEOFDAY) { static time_t last_sec = 0, last_usec = 0; |
