[libcxx-commits] [libcxx] 42d653d - [libcxx] Simplify rounding of durations in win32 __libcpp_thread_sleep_for

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 17 01:12:36 PDT 2021


Author: Martin Storsjö
Date: 2021-03-17T10:09:10+02:00
New Revision: 42d653d294a85ad3a5df1ba0827aeb1ecd99ebe3

URL: https://github.com/llvm/llvm-project/commit/42d653d294a85ad3a5df1ba0827aeb1ecd99ebe3
DIFF: https://github.com/llvm/llvm-project/commit/42d653d294a85ad3a5df1ba0827aeb1ecd99ebe3.diff

LOG: [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

Added: 
    

Modified: 
    libcxx/src/support/win32/thread_win32.cpp

Removed: 
    


################################################################################
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<milliseconds>(__ns + chrono::nanoseconds(999999));
+  // round-up to the nearest millisecond
+  chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__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<chrono::milliseconds>(__ns);
+  chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
   return WaitForSingleObjectEx(*(PHANDLE)__sem, __ms.count(), false) ==
          WAIT_OBJECT_0;
 }


        


More information about the libcxx-commits mailing list