diff options
author | 2018-09-11 18:29:53 +0000 | |
---|---|---|
committer | 2018-09-11 18:29:53 +0000 | |
commit | e933dfd56b2b1c88c8dcf4c47d7dabd4706764dd (patch) | |
tree | cd7e74d77951b26255308bb3b085180d83504687 /lib/libcxx/src/thread.cpp | |
parent | import of libc++ 6.0.0 (diff) | |
download | wireguard-openbsd-e933dfd56b2b1c88c8dcf4c47d7dabd4706764dd.tar.xz wireguard-openbsd-e933dfd56b2b1c88c8dcf4c47d7dabd4706764dd.zip |
merge libc++ 6.0.0 (bump lib major); ok patrick@, kettenis@
Diffstat (limited to 'lib/libcxx/src/thread.cpp')
-rw-r--r-- | lib/libcxx/src/thread.cpp | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/lib/libcxx/src/thread.cpp b/lib/libcxx/src/thread.cpp index d4977cd9a73..62b8e9cb8b4 100644 --- a/lib/libcxx/src/thread.cpp +++ b/lib/libcxx/src/thread.cpp @@ -24,14 +24,15 @@ # endif // defined(BSD) #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -#if !defined(_WIN32) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) # include <unistd.h> -#endif // !_WIN32 +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) #if defined(__NetBSD__) #pragma weak pthread_create // Do not create libpthread dependency #endif -#if defined(_WIN32) + +#if defined(_LIBCPP_WIN32API) #include <windows.h> #endif @@ -39,7 +40,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD thread::~thread() { - if (__t_ != 0) + if (!__libcpp_thread_isnull(&__t_)) terminate(); } @@ -47,32 +48,30 @@ void thread::join() { int ec = EINVAL; - if (__t_ != 0) + if (!__libcpp_thread_isnull(&__t_)) { ec = __libcpp_thread_join(&__t_); if (ec == 0) - __t_ = 0; + __t_ = _LIBCPP_NULL_THREAD; } -#ifndef _LIBCPP_NO_EXCEPTIONS + if (ec) - throw system_error(error_code(ec, system_category()), "thread::join failed"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_system_error(ec, "thread::join failed"); } void thread::detach() { int ec = EINVAL; - if (__t_ != 0) + if (!__libcpp_thread_isnull(&__t_)) { ec = __libcpp_thread_detach(&__t_); if (ec == 0) - __t_ = 0; + __t_ = _LIBCPP_NULL_THREAD; } -#ifndef _LIBCPP_NO_EXCEPTIONS + if (ec) - throw system_error(error_code(ec, system_category()), "thread::detach failed"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_system_error(ec, "thread::detach failed"); } unsigned @@ -93,14 +92,14 @@ thread::hardware_concurrency() _NOEXCEPT if (result < 0) return 0; return static_cast<unsigned>(result); -#elif defined(_WIN32) +#elif defined(_LIBCPP_WIN32API) SYSTEM_INFO info; GetSystemInfo(&info); return info.dwNumberOfProcessors; #else // defined(CTL_HW) && defined(HW_NCPU) // TODO: grovel through /proc or check cpuid on x86 and similar // instructions on other architectures. -# if defined(_MSC_VER) && ! defined(__clang__) +# if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("hardware_concurrency not yet implemented") # else # warning hardware_concurrency not yet implemented @@ -115,26 +114,9 @@ namespace this_thread void sleep_for(const chrono::nanoseconds& ns) { - using namespace chrono; - if (ns > nanoseconds::zero()) + if (ns > chrono::nanoseconds::zero()) { - seconds s = duration_cast<seconds>(ns); - timespec ts; - typedef decltype(ts.tv_sec) ts_sec; - _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max(); - if (s.count() < ts_sec_max) - { - ts.tv_sec = static_cast<ts_sec>(s.count()); - ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((ns-s).count()); - } - else - { - ts.tv_sec = ts_sec_max; - ts.tv_nsec = giga::num - 1; - } - - while (nanosleep(&ts, &ts) == -1 && errno == EINTR) - ; + __libcpp_thread_sleep_for(ns); } } |