Skip to content

Commit

Permalink
Avoid clock_gettime on pre-10.12 macOS versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ajkr committed Jul 16, 2019
1 parent ddcfb80 commit 8bd5ed5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion env/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// Get nano time includes
#if defined(OS_LINUX) || defined(OS_FREEBSD)
#elif defined(__MACH__)
#include <Availability.h>
#include <mach/clock.h>
#include <mach/mach.h>
#else
Expand Down Expand Up @@ -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<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
Expand Down

0 comments on commit 8bd5ed5

Please sign in to comment.