[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
Tue Jan 4 10:26:55 PST 2022
mcgrathr created this revision.
mcgrathr added reviewers: phosek, ldionne.
Herald added a subscriber: abrachet.
mcgrathr requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Use the zx_clock_get_monotonic system call directly rather than
going through the POSIX clock_gettime function. The libc function
is a trivial wrapper around the system call, and is not a standard C
function. Avoiding it reduces the Fuchsia libc ABI surface that
libc++ depends on.
Repository:
rG LLVM Github Monorepo
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.397333.patch
Type: text/x-patch
Size: 1321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220104/27b15ba9/attachment.bin>
More information about the libcxx-commits
mailing list