[libcxx-commits] [PATCH] D116606: [libcxx] Use Fuchsia-native monotonic clock for std::chrono::steady_clock

Roland McGrath via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 10 13:14:59 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGce167c6fb2ae: [libcxx] Use Fuchsia-native monotonic clock for std::chrono::steady_clock (authored by mcgrathr).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116606/new/

https://reviews.llvm.org/D116606

Files:
  libcxx/src/chrono.cpp


Index: libcxx/src/chrono.cpp
===================================================================
--- libcxx/src/chrono.cpp
+++ libcxx/src/chrono.cpp
@@ -44,6 +44,10 @@
 #  endif
 #endif // defined(_LIBCPP_WIN32API)
 
+#if defined(__Fuchsia__)
+#  include <zircon/syscalls.h>
+#endif
+
 #if __has_include(<mach/mach_time.h>)
 # include <mach/mach_time.h>
 #endif
@@ -266,7 +270,18 @@
   return steady_clock::time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
 }
 
-#elif defined(CLOCK_MONOTONIC)
+#  elif defined(__Fuchsia__)
+
+static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
+  // Implicitly link against the vDSO system call ABI without
+  // requiring the final link to specify -lzircon explicitly when
+  // statically linking libc++.
+#    pragma comment(lib, "zircon")
+
+  return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
+}
+
+#  elif defined(CLOCK_MONOTONIC)
 
 static steady_clock::time_point __libcpp_steady_clock_now() {
     struct timespec tp;
@@ -275,9 +290,9 @@
     return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
 }
 
-#else
-#   error "Monotonic clock not implemented on this platform"
-#endif
+#  else
+#    error "Monotonic clock not implemented on this platform"
+#  endif
 
 const bool steady_clock::is_steady;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116606.398724.patch
Type: text/x-patch
Size: 1321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220110/8a524664/attachment.bin>


More information about the libcxx-commits mailing list