[libcxx-commits] [PATCH] D98015: [libcxx] Simplify rounding of durations in win32 __libcpp_thread_sleep_for

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rG42d653d294a8: [libcxx] Simplify rounding of durations in win32 __libcpp_thread_sleep_for (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D98015?vs=328424&id=331174#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98015

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


Index: libcxx/src/support/win32/thread_win32.cpp
===================================================================
--- libcxx/src/support/win32/thread_win32.cpp
+++ libcxx/src/support/win32/thread_win32.cpp
@@ -246,10 +246,8 @@
 
 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_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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98015.331174.patch
Type: text/x-patch
Size: 1088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210317/893a47a7/attachment.bin>


More information about the libcxx-commits mailing list