aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2022-12-29 01:15:27 +0800
committerJia Tan <jiat0218@gmail.com>2022-12-30 23:34:31 +0800
commitf82294c8318a7a0990583d51ac5c7de682ad36ef (patch)
tree33c580f33a8684f6fcc6800dbdc52e2defa71497 /src/common
parentBuild: No longer require HAVE_DECL_CLOCK_MONOTONIC to always be set. (diff)
downloadxz-f82294c8318a7a0990583d51ac5c7de682ad36ef.tar.xz
liblzma: Includes sys/time.h conditionally in mythread
Previously, <sys/time.h> was always included, even if mythread only used clock_gettime. <time.h> is still needed even if clock_gettime is not used though because struct timespec is needed for mythread_condtime.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/mythread.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/common/mythread.h b/src/common/mythread.h
index 9be90d4e..a0dced19 100644
--- a/src/common/mythread.h
+++ b/src/common/mythread.h
@@ -100,12 +100,18 @@ mythread_sigmask(int how, const sigset_t *restrict set,
// Using pthreads //
////////////////////
-#include <sys/time.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
+// If clock_gettime() isn't available, use gettimeofday() from <sys/time.h>
+// as a fallback. gettimeofday() is in SUSv2 and thus is supported on all
+// relevant POSIX systems.
+#if !defined(HAVE_CLOCK_GETTIME)
+# include <sys/time.h>
+#endif
+
#define MYTHREAD_RET_TYPE void *
#define MYTHREAD_RET_VALUE NULL