[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
1773eec692.

Differential Revision: https://reviews.llvm.org/D98015
This commit is contained in:
Martin Storsjö 2021-02-26 16:13:38 +02:00
parent fd302e21b3
commit 42d653d294
1 changed files with 3 additions and 5 deletions

View File

@ -246,10 +246,8 @@ void __libcpp_thread_yield()
void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
{ {
using namespace chrono; // round-up to the nearest millisecond
// round-up to the nearest milisecond chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
milliseconds __ms =
duration_cast<milliseconds>(__ns + chrono::nanoseconds(999999));
// FIXME(compnerd) this should be an alertable sleep (WFSO or SleepEx) // FIXME(compnerd) this should be an alertable sleep (WFSO or SleepEx)
Sleep(__ms.count()); Sleep(__ms.count());
} }
@ -305,7 +303,7 @@ bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem,
chrono::nanoseconds const& __ns) 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) == return WaitForSingleObjectEx(*(PHANDLE)__sem, __ms.count(), false) ==
WAIT_OBJECT_0; WAIT_OBJECT_0;
} }