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

hfinkel at anl.gov hfinkel at anl.gov
Wed Mar 11 09:26:19 PDT 2015


================
Comment at: src/chrono.cpp:42
@@ -35,2 +41,3 @@
+#endif  // __APPLE__
 }
 
----------------
ed wrote:
> mclow.lists wrote:
> > Apple does not provide `clock_gettime`, but It's not clear to me that this should be an "Apple vs. everyone else" test.
> > 
> > Are there other systems that do not provide that call?
> While reading the code I assumed that every operating system supported by this source file except OS X had `clock_gettime`, but I forgot to take into account that the monotonic clock is optional through a compilation switch `_LIBCPP_HAS_NO_MONOTONIC_CLOCK`.
> 
> The updated patch no longer makes this false assumption. It will only call `clock_gettime` when `CLOCK_REALTIME` or `CLOCK_MONOTONIC` are set.
As a general note, there are many embedded-type systems that don't provide a monotonic clock. POSIX has a separate feature category for monotonic clock support: _POSIX_MONOTONIC_CLOCK -- and you must check for that, not just that CLOCK_MONOTONIC is defined (because there are systems on which CLOCK_MONOTONIC is defined, but not _POSIX_MONOTONIC_CLOCK, and calling clock_gettime with CLOCK_MONOTONIC will return EINVAL. Another option, perhaps, is to try it, and then call back to CLOCK_REALTIME if you get EINVAL.

http://reviews.llvm.org/D8253

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






More information about the cfe-commits mailing list