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

Ed Schouten ed at nuxi.nl
Wed Mar 11 09:32:26 PDT 2015


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

> Please upload your diffs with more context (i.e. `git diff -U999`)... it'll make the reviews a bit easier.


Sure! Will do that as of now. Still trying to get used to Phabricator.

> How about defining `_LIBCPP_HAS_NO_REALTIME_CLOCK`, similarly to the existing one for monotonic clocks in `include/__config` under the appropriate guards? (i.e. it would be defined on `__APPLE__`, and anywhere else that doesn't have `clock_gettime(CLOCK_REALTIME, x)`)


So it is important to keep in mind that `_LIBCPP_HAS_NO_MONOTONIC_CLOCK` does not indicate whether `CLOCK_MONOTONIC` is present or not. It is used to indicate that the system provides some method of obtaining a monotonic clock. The `_LIBCPP_HAS_NO_MONOTONIC_CLOCK` flag is not set on OS X, even though there is a monotonic clock.

Using that logic `_LIBCPP_HAS_NO_REALTIME_CLOCK` would imply that the system has no real-time clock at all.


================
Comment at: src/chrono.cpp:72
@@ -53,2 +71,3 @@
 
-#ifdef __APPLE__
+#ifdef CLOCK_MONOTONIC
+
----------------
jroelofs wrote:
> This is already taken care of where `_LIBCPP_HAS_NO_MONOTONIC_CLOCK` is defined. I don't think there's a need to change anything around the steady_clock implementation.
The intent of this change was to be a bit more consistent with the change to system_clock. First try to use the POSIX API (`clock_gettime`) and only if that one is unavailable fall back to custom APIs specific to a smaller set of operating systems.

http://reviews.llvm.org/D8253

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






More information about the cfe-commits mailing list