[PATCH] [libcxx] Partially address a FIXME in steady_clock::now()

Jon Roelofs jonathan at codesourcery.com
Wed Aug 13 07:47:40 PDT 2014


On systems without a monotonic clock, it's probably better to not have steady_clock than to have a non-conforming one.

Since steady_clock is used for timed mutexes and such, something like: http://reviews.llvm.org/D3969 is probably necessary to actually build libc++ without a a monotonic clock. I'll be picking that patch up for upstreaming again here shortly.

http://reviews.llvm.org/D4045

Files:
  include/__config
  include/chrono
  src/chrono.cpp

Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -639,6 +639,11 @@
 #  define _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 1
 #endif
 
+#if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) && \
+    (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0)
+#define _LIBCPP_HAS_MONOTONIC_CLOCK 1
+#endif
+
 #ifndef _LIBCPP_STD_VER
 #  if  __cplusplus <= 201103L
 #    define _LIBCPP_STD_VER 11
Index: include/chrono
===================================================================
--- include/chrono
+++ include/chrono
@@ -926,6 +926,7 @@
     static time_point from_time_t(time_t __t) _NOEXCEPT;
 };
 
+#if _LIBCPP_HAS_MONOTONIC_CLOCK
 class _LIBCPP_TYPE_VIS steady_clock
 {
 public:
@@ -939,6 +940,9 @@
 };
 
 typedef steady_clock high_resolution_clock;
+#else
+typedef system_clock high_resolution_clock;
+#endif
 
 } // chrono
 
Index: src/chrono.cpp
===================================================================
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -46,6 +46,7 @@
     return system_clock::time_point(seconds(t));
 }
 
+#if _LIBCPP_HAS_MONOTONIC_CLOCK
 // steady_clock
 
 const bool steady_clock::is_steady;
@@ -108,11 +109,6 @@
 }
 
 #else  // __APPLE__
-// FIXME: We assume that clock_gettime(CLOCK_MONOTONIC) works on
-// non-apple systems.  Instead, we should check _POSIX_TIMERS and
-// _POSIX_MONOTONIC_CLOCK and fall back to something else if those
-// don't exist.
-
 // Warning:  If this is not truly steady, then it is non-conforming.  It is
 //  better for it to not exist and have the rest of libc++ use system_clock
 //  instead.
@@ -127,6 +123,8 @@
 }
 #endif  // __APPLE__
 
+#endif // _LIBCPP_HAS_MONOTONIC_CLOCK
+
 }
 
 _LIBCPP_END_NAMESPACE_STD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4045.12449.patch
Type: text/x-patch
Size: 1758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140813/8e661bf9/attachment.bin>


More information about the cfe-commits mailing list