================
Comment at: src/chrono.cpp:42
@@ -35,2 +41,3 @@
+#endif  // __APPLE__
 }
 
----------------
hfinkel wrote:
> 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.
> 
@hfinkel: Yes. That's good to keep in mind. There's also _POSIX_MONOTONIC_CLOCK.

Though we could test against _POSIX_MONOTONIC_CLOCK, I would actually suggest 
against that in this case. If a system has MONOTONIC_CLOCK but has 
_POSIX_MONOTONIC_CLOCK undefined or set to 0, we will just build a steady_clock 
that will fail at run-time. There is nothing to fall back to in those cases 
anyway.

Testing for _POSIX_MONOTONIC_CLOCK is a bit annoying, because it means we need 
to add some more litter to the code as well:

#ifdef _WIN32
#include <unistd.h> // For _POSIX_MONOTONIC_CLOCK
#endif

http://reviews.llvm.org/D8253

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



_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to