From a75fccd1805d420408074beb0d82d453e4af6a79 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 15 Jul 2019 18:52:27 +0000 Subject: [PATCH] Avoid clock_gettime on pre-10.12 macOS versions On older macOS like 10.10 we saw the following compiler error: ``` /go/src/github.com/cockroachdb/cockroach/c-deps/rocksdb/env/env_posix.cc:845:19: error: use of undeclared identifier 'CLOCK_THREAD_CPUTIME_ID' clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); ^ ``` According to mac's `man clock_gettime`: "These functions first appeared in Mac OSX 10.12". So we should not try to compile it on earlier versions. Test Plan: verified it compiles now on 10.10. Also did some investigation to ensure it does not cause regression on macOS 10.12+, although I do not have access to such an environment to really test. --- env/env_posix.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/env/env_posix.cc b/env/env_posix.cc index 387c0279397..09cacdd1cc9 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -33,6 +33,7 @@ // Get nano time includes #if defined(OS_LINUX) || defined(OS_FREEBSD) #elif defined(__MACH__) +#include #include #include #else @@ -839,7 +840,7 @@ class PosixEnv : public Env { uint64_t NowCPUNanos() override { #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX) || \ - defined(__MACH__) + (defined(__MACH__) && defined(__MAC_10_12)) struct timespec ts; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); return static_cast(ts.tv_sec) * 1000000000 + ts.tv_nsec;