diff options
Diffstat (limited to 'contrib/libc++/src/thread.cpp')
-rw-r--r-- | contrib/libc++/src/thread.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/contrib/libc++/src/thread.cpp b/contrib/libc++/src/thread.cpp index b2bd07e..c6f6748 100644 --- a/contrib/libc++/src/thread.cpp +++ b/contrib/libc++/src/thread.cpp @@ -13,8 +13,8 @@ #include "future" #include "limits" #include <sys/types.h> -#if !_WIN32 -#if !__sun__ && !__linux__ +#if !defined(_WIN32) +#if !defined(__sun__) && !defined(__linux__) #include <sys/sysctl.h> #else #include <unistd.h> @@ -36,6 +36,8 @@ thread::join() #ifndef _LIBCPP_NO_EXCEPTIONS if (ec) throw system_error(error_code(ec, system_category()), "thread::join failed"); +#else + (void)ec; #endif // _LIBCPP_NO_EXCEPTIONS __t_ = 0; } @@ -65,13 +67,15 @@ thread::hardware_concurrency() _NOEXCEPT std::size_t s = sizeof(n); sysctl(mib, 2, &n, &s, 0, 0); return n; -#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN) +#elif (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN)) || defined(EMSCRIPTEN) long result = sysconf(_SC_NPROCESSORS_ONLN); // sysconf returns -1 if the name is invalid, the option does not exist or // does not have a definite limit. - if (result == -1) + // if sysconf returns some other negative number, we have no idea + // what is going on. Default to something safe. + if (result < 0) return 0; - return result; + return static_cast<unsigned>(result); #else // defined(CTL_HW) && defined(HW_NCPU) // TODO: grovel through /proc or check cpuid on x86 and similar // instructions on other architectures. |