[PATCH] Use clock_gettime()'s CLOCK_REALTIME instead of gettimeofday() where possible

Ed Schouten ed at nuxi.nl
Wed Mar 11 08:43:39 PDT 2015


In http://reviews.llvm.org/D8253#138862, @jroelofs wrote:

> I think the new bits here need to be guarded on a check for `#if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)`, and otherwise fall back on the original implementation.


Checking against _POSIX_TIMERS would be a bit problematic in my specific case. The issue with _POSIX_TIMERS is that it actually covers two separate features:

- The clock_*() API (gettime, getres, nanosleep),
- The timer_*() API.

CloudABI only supports the former (as there is no signal handling), meaning we had to set _POSIX_TIMERS to -1. We could use:

`#if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) || defined(__CloudABI__)`

But that might be overdoing it. Maybe it is sufficient to just use:

`#ifdef CLOCK_REALTIME`

I could also invert the logic for the monotonic clock. Test against CLOCK_MONOTONIC first. Only if that one is absent, resort to testing against __APPLE__. Otherwise, throw a compiler error.

Would that be all right?


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D8253

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list