mirror of https://git.tukaani.org/xz.git
xz: Use clock_gettime() even if CLOCK_MONOTONIC isn't available.
mythread.h and thus liblzma already does it.
This commit is contained in:
parent
2e02877288
commit
610dde15a8
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
# include <time.h>
|
# include <time.h>
|
||||||
#else
|
#else
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
|
@ -35,14 +35,19 @@ static uint64_t next_flush;
|
||||||
static uint64_t
|
static uint64_t
|
||||||
mytime_now(void)
|
mytime_now(void)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
|
struct timespec tv;
|
||||||
|
|
||||||
|
# ifdef HAVE_CLOCK_MONOTONIC
|
||||||
// If CLOCK_MONOTONIC was available at compile time but for some
|
// If CLOCK_MONOTONIC was available at compile time but for some
|
||||||
// reason isn't at runtime, fallback to CLOCK_REALTIME which
|
// reason isn't at runtime, fallback to CLOCK_REALTIME which
|
||||||
// according to POSIX is mandatory for all implementations.
|
// according to POSIX is mandatory for all implementations.
|
||||||
static clockid_t clk_id = CLOCK_MONOTONIC;
|
static clockid_t clk_id = CLOCK_MONOTONIC;
|
||||||
struct timespec tv;
|
|
||||||
while (clock_gettime(clk_id, &tv))
|
while (clock_gettime(clk_id, &tv))
|
||||||
clk_id = CLOCK_REALTIME;
|
clk_id = CLOCK_REALTIME;
|
||||||
|
# else
|
||||||
|
clock_gettime(CLOCK_REALTIME, &tv);
|
||||||
|
# endif
|
||||||
|
|
||||||
return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_nsec / 1000000);
|
return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_nsec / 1000000);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -56,8 +56,7 @@
|
||||||
// polls the time and the SIGTSTP handling adds slight overhead to
|
// polls the time and the SIGTSTP handling adds slight overhead to
|
||||||
// that code. Most (all?) systems that have SIGTSTP also have SIGALRM
|
// that code. Most (all?) systems that have SIGTSTP also have SIGALRM
|
||||||
// so this requirement won't exclude many systems.
|
// so this requirement won't exclude many systems.
|
||||||
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC) \
|
#if defined(HAVE_CLOCK_GETTIME) && defined(SIGTSTP) && defined(SIGALRM)
|
||||||
&& defined(SIGTSTP) && defined(SIGALRM)
|
|
||||||
# define USE_SIGTSTP_HANDLER 1
|
# define USE_SIGTSTP_HANDLER 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue