[libcxx-commits] [libcxx] 7e6f2b7 - [libc++] Fix clock selection in chrono.cpp and filesystem_clock.cpp
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 12 15:07:39 PDT 2023
Author: Louis Dionne
Date: 2023-07-12T18:07:21-04:00
New Revision: 7e6f2b749bf784ddf0c1287835bb3df8749d2b9b
URL: https://github.com/llvm/llvm-project/commit/7e6f2b749bf784ddf0c1287835bb3df8749d2b9b
DIFF: https://github.com/llvm/llvm-project/commit/7e6f2b749bf784ddf0c1287835bb3df8749d2b9b.diff
LOG: [libc++] Fix clock selection in chrono.cpp and filesystem_clock.cpp
This patch partly reverts the change that was made in 5f1ba3a502
regarding the clock selection on Apple platforms. It turns out that
gettimeofday() is marked as obsolete by POSIX and clock_gettime() is
recommended instead. Since both are equivalent for our purposes,
prefer using clock_gettime() even on Apple platforms.
Differential Revision: https://reviews.llvm.org/D155022
Added:
Modified:
libcxx/src/chrono.cpp
libcxx/src/filesystem/filesystem_clock.cpp
Removed:
################################################################################
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 415988b2314d7f..0990d8dc181c23 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -31,8 +31,8 @@
# include <sys/time.h> // for gettimeofday and timeval
#endif
-#if !defined(__APPLE__) && defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
-# define _LIBCPP_USE_CLOCK_GETTIME
+#if defined(__APPLE__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+# define _LIBCPP_HAS_CLOCK_GETTIME
#endif
#if defined(_LIBCPP_WIN32API)
@@ -116,7 +116,7 @@ static system_clock::time_point __libcpp_system_clock_now() {
return system_clock::time_point(duration_cast<system_clock::duration>(d - nt_to_unix_epoch));
}
-#elif defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
static system_clock::time_point __libcpp_system_clock_now() {
struct timespec tp;
@@ -226,7 +226,7 @@ static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
}
-# elif defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+# elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
static steady_clock::time_point __libcpp_steady_clock_now() {
struct timespec tp;
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp
index beecd5d4a5ea35..9ea070bf75c3ba 100644
--- a/libcxx/src/filesystem/filesystem_clock.cpp
+++ b/libcxx/src/filesystem/filesystem_clock.cpp
@@ -27,8 +27,8 @@
# include <sys/time.h> // for gettimeofday and timeval
#endif
-#if !defined(__APPLE__) && defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
-# define _LIBCPP_USE_CLOCK_GETTIME
+#if defined(__APPLE__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+# define _LIBCPP_HAS_CLOCK_GETTIME
#endif
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
@@ -44,7 +44,7 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept {
detail::TimeSpec tp = detail::filetime_to_timespec(time);
return time_point(__secs(tp.tv_sec) +
chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
-#elif defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
typedef chrono::duration<rep, nano> __nsecs;
struct timespec tp;
if (0 != clock_gettime(CLOCK_REALTIME, &tp))
@@ -56,7 +56,7 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept {
timeval tv;
gettimeofday(&tv, 0);
return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec));
-#endif // CLOCK_REALTIME
+#endif
}
_LIBCPP_END_NAMESPACE_FILESYSTEM
More information about the libcxx-commits
mailing list