threading_support: make __thread_sleep_for be alertable

On Windows, we were using `Sleep` which is not alertable.  This means
that if the thread was used for a user APC or WinProc handling and
thread::sleep was used, we could potentially dead lock.  Use `SleepEx`
with an alertable sleep, resuming until the time has expired if we are
awoken early.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@295329 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool
2017-02-16 15:47:45 +00:00
parent 2c477cb41a
commit e80bd1ab0b

View File

@@ -589,11 +589,14 @@ void __libcpp_thread_yield()
void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
{
using namespace chrono;
using namespace _VSTD::chrono;
// round-up to the nearest milisecond
milliseconds __ms =
duration_cast<milliseconds>(__ns + chrono::nanoseconds(999999));
Sleep(__ms.count());
auto start = system_clock::now();
while (::SleepEx((__ms - (system_clock::now() - start)).count(),
TRUE) == WAIT_IO_COMPLETION);
}
// Thread Local Storage