diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2020-04-16 22:14:29 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2020-04-16 22:36:29 +0300 |
commit | 4011b4b5c533c5030a993e3680e01b7b7d3f7fc5 (patch) | |
tree | 10b9e522d696d77e4fa3b54d7232dfd1752e2b40 | |
parent | ac81df303d29aa83cdc146f3433647360eb4deff (diff) | |
download | bdwgc-4011b4b5c533c5030a993e3680e01b7b7d3f7fc5.tar.gz |
Use clock_gettime() instead of clock() on Cygwin and Linux
Also, CLOCK_MONOTONIC is used on Nintendo Switch (instead of
CLOCK_REALTIME).
* include/private/gc_priv.h [!NO_CLOCK && !BSD_TIME && !(MSWIN32
|| MSWINCE || WINXP_USE_PERF_COUNTER) && !NN_PLATFORM_CTR
&& NINTENDO_SWITCH && _POSIX_MONOTONIC_CLOCK] (GET_TIME): Pass
CLOCK_MONOTONIC to clock_gettime instead of CLOCK_REALTIME; remove
TODO item.
* include/private/gc_priv.h [!NO_CLOCK && !BSD_TIME && !(MSWIN32
|| MSWINCE || WINXP_USE_PERF_COUNTER) && !NN_PLATFORM_CTR && CYGWIN32]
(CLOCK_TYPE, CLOCK_TYPE_INITIALIZER, GET_TIME, MS_TIME_DIFF,
NS_FRAC_TIME_DIFF): Define macro (in the same way as for
NINTENDO_SWITCH).
-rw-r--r-- | include/private/gc_priv.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index bd56da48..cabd7598 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -496,16 +496,23 @@ EXTERN_C_END # define MS_TIME_DIFF(a,b) ((unsigned long)n3ds_convert_tick_to_ms((a)-(b))) # define NS_FRAC_TIME_DIFF(a, b) 0UL /* TODO: implement it */ -#elif defined(NINTENDO_SWITCH) +#elif defined(NINTENDO_SWITCH) || defined(CYGWIN32) || defined(LINUX) # include <time.h> # define CLOCK_TYPE struct timespec # define CLOCK_TYPE_INITIALIZER { 0, 0 } -# define GET_TIME(x) \ +# if defined(_POSIX_MONOTONIC_CLOCK) +# define GET_TIME(x) \ + do { \ + if (clock_gettime(CLOCK_MONOTONIC, &x) == -1) \ + ABORT("clock_gettime failed"); \ + } while (0) +# else +# define GET_TIME(x) \ do { \ - /* TODO: Use CLOCK_MONOTONIC */ \ if (clock_gettime(CLOCK_REALTIME, &x) == -1) \ ABORT("clock_gettime failed"); \ } while (0) +# endif # define MS_TIME_DIFF(a, b) \ /* a.tv_nsec - b.tv_nsec is in range -1e9 to 1e9 exclusively */ \ ((unsigned long)((a).tv_nsec + (1000000L*1000 - (b).tv_nsec)) / 1000000UL \ |