Fallback to time(0) in mg_millis()

This commit is contained in:
Sergey Lyubka 2021-12-21 22:04:03 +00:00
parent bf7fc1d5a9
commit 25a1a24890
2 changed files with 6 additions and 2 deletions

View File

@ -4475,7 +4475,7 @@ int64_t mg_millis(void) {
double ticks_to_nanos = (double) timebase.numer / timebase.denom;
uint64_t uptime_nanos = (uint64_t) (ticks_to_nanos * ticks);
return (int64_t) (uptime_nanos / 1000000);
#else
#elif MG_ARCH == MG_ARCH_UNIX
struct timespec ts;
#ifdef _POSIX_MONOTONIC_CLOCK
#ifdef CLOCK_MONOTONIC_RAW
@ -4487,6 +4487,8 @@ int64_t mg_millis(void) {
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return ((int64_t) ts.tv_sec * 1000 + (int64_t) ts.tv_nsec / 1000000);
#else
return time(NULL) * 1000;
#endif
}

View File

@ -317,7 +317,7 @@ int64_t mg_millis(void) {
double ticks_to_nanos = (double) timebase.numer / timebase.denom;
uint64_t uptime_nanos = (uint64_t) (ticks_to_nanos * ticks);
return (int64_t) (uptime_nanos / 1000000);
#else
#elif MG_ARCH == MG_ARCH_UNIX
struct timespec ts;
#ifdef _POSIX_MONOTONIC_CLOCK
#ifdef CLOCK_MONOTONIC_RAW
@ -329,5 +329,7 @@ int64_t mg_millis(void) {
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return ((int64_t) ts.tv_sec * 1000 + (int64_t) ts.tv_nsec / 1000000);
#else
return time(NULL) * 1000;
#endif
}