summaryrefslogtreecommitdiffstats
path: root/programs/util.h
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2018-01-16 18:21:37 (GMT)
committerYann Collet <cyan@fb.com>2018-01-16 18:21:37 (GMT)
commit7dba09af47dd3daa1562a6332a643a1a59dba4a8 (patch)
treed017471f7d2bee1891b34f952fdb44385ccc21a7 /programs/util.h
parentb077a99347a384225d03f5458c2b57bedb134c62 (diff)
downloadlz4-7dba09af47dd3daa1562a6332a643a1a59dba4a8.zip
lz4-7dba09af47dd3daa1562a6332a643a1a59dba4a8.tar.gz
lz4-7dba09af47dd3daa1562a6332a643a1a59dba4a8.tar.bz2
use more restrictive conditions for clock_gettime()
Diffstat (limited to 'programs/util.h')
-rw-r--r--programs/util.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/programs/util.h b/programs/util.h
index fc7f63e..a3576d7 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -141,6 +141,7 @@ extern "C" {
* Time functions
******************************************/
#if defined(_WIN32) /* Windows */
+
typedef LARGE_INTEGER UTIL_time_t;
UTIL_STATIC UTIL_time_t UTIL_getTime(void) { UTIL_time_t x; QueryPerformanceCounter(&x); return x; }
UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd)
@@ -165,7 +166,9 @@ extern "C" {
}
return 1000000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
}
+
#elif defined(__APPLE__) && defined(__MACH__)
+
#include <mach/mach_time.h>
typedef U64 UTIL_time_t;
UTIL_STATIC UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); }
@@ -189,7 +192,9 @@ extern "C" {
}
return ((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom);
}
-#elif (PLATFORM_POSIX_VERSION >= 200112L)
+
+#elif (PLATFORM_POSIX_VERSION >= 200112L) && (defined __UCLIBC__ || ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2))
+
#include <time.h>
typedef struct timespec UTIL_time_t;
UTIL_STATIC UTIL_time_t UTIL_getTime(void)
@@ -227,7 +232,9 @@ extern "C" {
nano += diff.tv_nsec;
return nano;
}
+
#else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */
+
typedef clock_t UTIL_time_t;
UTIL_STATIC UTIL_time_t UTIL_getTime(void) { return clock(); }
UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }