mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
time.c: use clock_gettime() if possible.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user