Skip to content

Commit 42d653d

Browse files
committed
[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 1773eec. Differential Revision: https://reviews.llvm.org/D98015
1 parent fd302e2 commit 42d653d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

libcxx/src/support/win32/thread_win32.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,8 @@ void __libcpp_thread_yield()
246246

247247
void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
248248
{
249-
using namespace chrono;
250-
// round-up to the nearest milisecond
251-
milliseconds __ms =
252-
duration_cast<milliseconds>(__ns + chrono::nanoseconds(999999));
249+
// round-up to the nearest millisecond
250+
chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
253251
// FIXME(compnerd) this should be an alertable sleep (WFSO or SleepEx)
254252
Sleep(__ms.count());
255253
}
@@ -305,7 +303,7 @@ bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
305303
bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem,
306304
chrono::nanoseconds const& __ns)
307305
{
308-
chrono::milliseconds __ms = std::chrono::ceil<chrono::milliseconds>(__ns);
306+
chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
309307
return WaitForSingleObjectEx(*(PHANDLE)__sem, __ms.count(), false) ==
310308
WAIT_OBJECT_0;
311309
}

0 commit comments

Comments
 (0)