X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/70221324f0971ccf4ac4017da5e34297b1e2af65..8039afaf2c8b0a9bb3359206719859b0da53ea7c:/rand/noise.c diff --git a/rand/noise.c b/rand/noise.c index f01af651..de120d8b 100644 --- a/rand/noise.c +++ b/rand/noise.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -65,12 +66,27 @@ #define NOISE_KIDLIFE 100000 /* @noise_filter@ child lifetime */ +#if HAVE_CLOCK_GETTIME && _POSIX_TIMERS > 0 +# define TIMESTRUCT timespec +# define tv_SEC tv_sec +# define tv_FRAC tv_nsec +# define TIMERES 1000000000 +# if _POSIX_MONOTONIC_CLOCK > 0 +# define GETTIME(tv) (clock_gettime(CLOCK_MONOTONIC, (tv))) +# else +# define GETTIME(tv) (clock_gettime(CLOCK_REALTIME, (tv))) +# endif +# define TOTIMEVAL(tv, xx) \ + ((tv)->tv_sec = (xx)->tv_sec, \ + (tv)->tv_usec = ((xx)->tv_nsec + 500)/1000) +#else # define TIMESTRUCT timeval # define tv_SEC tv_sec # define tv_FRAC tv_usec # define TIMERES 1000000 # define GETTIME(tv) (gettimeofday((tv), 0)) # define TOTIMEVAL(tv, xx) (*(tv) = *(xx)) +#endif /*----- Noise source definition -------------------------------------------*/