diff options
| author | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-02-16 15:47:45 +0000 |
|---|---|---|
| committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-02-16 15:47:45 +0000 |
| commit | 305b4f2ba9f93b692863b1a1b777e4fdc4ba6e01 (patch) | |
| tree | c3adf452292dcb3eb9f3c4db2c0e78b0cfaa00bb /libcxx/include/__threading_support | |
| parent | 7dc6e51ef560887ecc0adbff2428168139f34e28 (diff) | |
| download | bcm5719-llvm-305b4f2ba9f93b692863b1a1b777e4fdc4ba6e01.tar.gz bcm5719-llvm-305b4f2ba9f93b692863b1a1b777e4fdc4ba6e01.zip | |
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.
llvm-svn: 295329
Diffstat (limited to 'libcxx/include/__threading_support')
| -rw-r--r-- | libcxx/include/__threading_support | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support index 1e8be3fdab7..8b0b2eda9b0 100644 --- a/libcxx/include/__threading_support +++ b/libcxx/include/__threading_support @@ -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 |

