From 42d653d294a85ad3a5df1ba0827aeb1ecd99ebe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 26 Feb 2021 16:13:38 +0200 Subject: [PATCH] [libcxx] Simplify rounding of durations in win32 __libcpp_thread_sleep_for Also fix a comment typo, and remove a superfluous "std::" qualififcation in __libcpp_semaphore_wait_timed for consistency. This mirrors what was suggested in review of 1773eec6928f4e37b377e23b84d7a2a07d0d1d0d. Differential Revision: https://reviews.llvm.org/D98015 --- libcxx/src/support/win32/thread_win32.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libcxx/src/support/win32/thread_win32.cpp b/libcxx/src/support/win32/thread_win32.cpp index 2b1aa5635ac7..63c5aa65374f 100644 --- a/libcxx/src/support/win32/thread_win32.cpp +++ b/libcxx/src/support/win32/thread_win32.cpp @@ -246,10 +246,8 @@ void __libcpp_thread_yield() void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) { - using namespace chrono; - // round-up to the nearest milisecond - milliseconds __ms = - duration_cast(__ns + chrono::nanoseconds(999999)); + // round-up to the nearest millisecond + chrono::milliseconds __ms = chrono::ceil(__ns); // FIXME(compnerd) this should be an alertable sleep (WFSO or SleepEx) Sleep(__ms.count()); } @@ -305,7 +303,7 @@ bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem) bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns) { - chrono::milliseconds __ms = std::chrono::ceil(__ns); + chrono::milliseconds __ms = chrono::ceil(__ns); return WaitForSingleObjectEx(*(PHANDLE)__sem, __ms.count(), false) == WAIT_OBJECT_0; }