[libcxx] r291331 - thread: implement sleep_for on Windows
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 6 18:48:30 PST 2017
Author: compnerd
Date: Fri Jan 6 20:48:30 2017
New Revision: 291331
URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
Log:
thread: implement sleep_for on Windows
Windows does not provide an implementation of `nanosleep`. Round up the
time duration to the nearest ms and use `Sleep`. Although this may
over-sleep, there is no hard real-time guarantee on the wake, so
sleeping a bit more is better than under-sleeping as it within the
specification.
Modified:
libcxx/trunk/src/thread.cpp
Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=291331&r1=291330&r2=291331&view=diff
==============================================================================
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Fri Jan 6 20:48:30 2017
@@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
using namespace chrono;
if (ns > nanoseconds::zero())
{
+#if defined(_LIBCPP_WIN32API)
+ milliseconds ms = duration_cast<milliseconds>(ns);
+ if (ns > duration_cast<nanoseconds>(ms))
+ ++ms;
+ Sleep(ms.count());
+#else
seconds s = duration_cast<seconds>(ns);
timespec ts;
typedef decltype(ts.tv_sec) ts_sec;
@@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)
while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
;
+#endif
}
}
More information about the cfe-commits
mailing list