[cfe-commits] [libcxx] r161190 - in /libcxx/trunk: src/thread.cpp www/results.Linux.html

Howard Hinnant hhinnant at apple.com
Thu Aug 2 11:17:49 PDT 2012


Author: hhinnant
Date: Thu Aug  2 13:17:49 2012
New Revision: 161190

URL: http://llvm.org/viewvc/llvm-project?rev=161190&view=rev
Log:
Andrew Morrow: The attached patch is an attempt to implement
std::thread::hardware_concurrency for platforms that don't offer
sysctl, but do provide a POSIX sysconf and _SC_NPROCESSORS_ONLN.

Modified:
    libcxx/trunk/src/thread.cpp
    libcxx/trunk/www/results.Linux.html

Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=161190&r1=161189&r2=161190&view=diff
==============================================================================
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Thu Aug  2 13:17:49 2012
@@ -12,9 +12,13 @@
 #include "vector"
 #include "future"
 #include <sys/types.h>
-#if !_WIN32 && !__sun__
+#if !_WIN32
+#if !__sun__ && !__linux__
 #include <sys/sysctl.h>
-#endif // _WIN32
+#else
+#include <unistd.h>
+#endif // !__sun__ && !__linux__
+#endif // !_WIN32
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -60,6 +64,11 @@
     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)
+    long result = sysconf(_SC_NPROCESSORS_ONLN);
+    if (result < 0 || result > UINT_MAX)
+        result = 0;
+    return result;
 #else  // defined(CTL_HW) && defined(HW_NCPU)
     // TODO: grovel through /proc or check cpuid on x86 and similar
     // instructions on other architectures.

Modified: libcxx/trunk/www/results.Linux.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/results.Linux.html?rev=161190&r1=161189&r2=161190&view=diff
==============================================================================
--- libcxx/trunk/www/results.Linux.html (original)
+++ libcxx/trunk/www/results.Linux.html Thu Aug  2 13:17:49 2012
@@ -113,13 +113,6 @@
  c.strings/
   cuchar.pass.cpp: Can't find cuchar header
   version_cuchar.pass.cpp: idem.
-thread/
- thread.threads/
-  thread.thread.class/
-   thread.thread.static/
-    hardware_concurrency.pass.cpp: Fails due to
-     std::hardware_concurrency unimplemented for non-BSD
-     systems. Patch in progress.
 utilities/
  memory/
   unique.ptr/





More information about the cfe-commits mailing list