Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2007-12-19 05:45:02


Author: anthonyw
Date: 2007-12-19 05:45:01 EST (Wed, 19 Dec 2007)
New Revision: 42168
URL: http://svn.boost.org/trac/boost/changeset/42168

Log:
Implement hardware_concurrency for pthread
Added:
   trunk/libs/thread/test/test_hardware_concurrency.cpp (contents, props changed)
Text files modified:
   trunk/libs/thread/src/pthread/thread.cpp | 11 ++++++++++-
   trunk/libs/thread/test/Jamfile.v2 | 1 +
   2 files changed, 11 insertions(+), 1 deletions(-)

Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2007-12-19 05:45:01 EST (Wed, 19 Dec 2007)
@@ -13,6 +13,9 @@
 #include <boost/thread/locks.hpp>
 #include <boost/thread/once.hpp>
 #include <boost/thread/tss.hpp>
+#ifdef __linux__
+#include <sys/sysinfo.h>
+#endif
 
 #include "timeconv.inl"
 
@@ -408,7 +411,13 @@
 
     unsigned thread::hardware_concurrency()
     {
- return 1;
+#if defined(PTW32_VERSION) || defined(__hpux)
+ return pthread_num_processors_np();
+#elif defined(__linux__)
+ return get_nprocs;
+#else
+ return 0;
+#endif
     }
 
     thread::id thread::get_id() const

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2007-12-19 05:45:01 EST (Wed, 19 Dec 2007)
@@ -36,6 +36,7 @@
     test-suite "threads"
         : [ thread-run test_thread.cpp ]
           [ thread-run test_thread_id.cpp ]
+ [ thread-run test_hardware_concurrency.cpp ]
           [ thread-run test_thread_move.cpp ]
           [ thread-run test_move_function.cpp ]
           [ thread-run test_mutex.cpp ]

Added: trunk/libs/thread/test/test_hardware_concurrency.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/test_hardware_concurrency.cpp 2007-12-19 05:45:01 EST (Wed, 19 Dec 2007)
@@ -0,0 +1,21 @@
+// Copyright (C) 2007 Anthony Williams
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <boost/thread/thread.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread/mutex.hpp>
+
+void test_hardware_concurrency_is_non_zero()
+{
+ BOOST_CHECK(boost::thread::hardware_concurrency()!=0);
+}
+
+boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
+{
+ boost::unit_test_framework::test_suite* test =
+ BOOST_TEST_SUITE("Boost.Threads: hardware concurrency test suite");
+
+ test->add(BOOST_TEST_CASE(test_hardware_concurrency_is_non_zero));
+ return test;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk