activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r824956 - in /activemq/activemq-cpp/trunk/activemq-cpp: configure.ac src/main/decaf/lang/System.cpp src/main/decaf/lang/System.h src/test/decaf/lang/SystemTest.cpp src/test/decaf/lang/SystemTest.h
Date Tue, 13 Oct 2009 22:24:16 GMT
Author: tabish
Date: Tue Oct 13 22:24:15 2009
New Revision: 824956

URL: http://svn.apache.org/viewvc?rev=824956&view=rev
Log:
Add first cut at System.availableProcessors and unit test it.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac?rev=824956&r1=824955&r2=824956&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/configure.ac (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/configure.ac Tue Oct 13 22:24:15 2009
@@ -110,6 +110,8 @@
 AC_CHECK_HEADERS([sys/time.h])
 AC_CHECK_HEADERS([sys/timeb.h])
 AC_CHECK_HEADERS([sys/wait.h])
+AC_CHECK_HEADERS([sys/types.h])
+AC_CHECK_HEADERS([sys/sysctl.h])
 AC_CHECK_HEADERS([sys/resource.h])
 AC_CHECK_HEADERS([pthread.h])
 AC_CHECK_HEADERS([errno.h])

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp?rev=824956&r1=824955&r2=824956&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp Tue Oct 13 22:24:15
2009
@@ -38,6 +38,12 @@
 #ifdef HAVE_TIME_H
 #include <time.h>
 #endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
 
 #include <cstdlib>
 
@@ -283,3 +289,40 @@
 }
 
 #endif
+
+////////////////////////////////////////////////////////////////////////////////
+int System::availableProcessors() {
+
+    int numCpus = 1;
+
+#if defined(_WIN32)
+
+    SYSTEM_INFO sysInfo;
+    ::GetSystemInfo( &sysInfo );
+    numCpus = sysInfo.dwNumberOfProcessors;
+
+#elif defined(__APPLE__)
+
+    // derived from examples in the sysctl(3) man page from FreeBSD
+    int mib[2];
+    std::size_t len;
+
+    mib[0] = CTL_HW;
+    mib[1] = HW_NCPU;
+    len = sizeof(numCpus);
+    sysctl(mib, 2, &numCpus, &len, NULL, 0);
+
+#else
+
+    // returns number of online(_SC_NPROCESSORS_ONLN) processors, number configured(_SC_NPROCESSORS_CONF)
+    // may be more than online
+    numCpus = sysconf( _SC_NPROCESSORS_ONLN );
+
+#endif
+
+    if( numCpus < 1 ) {
+        numCpus = 1;
+    }
+
+    return numCpus;
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h?rev=824956&r1=824955&r2=824956&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h Tue Oct 13 22:24:15
2009
@@ -109,6 +109,17 @@
          */
         static long long nanoTime();
 
+        /**
+         * Returns the number of processors available for exection of Decaf Threads.
+         *
+         * This value may change during a particular execution of a Decaf based application.
Applications
+         * that are sensitive to the number of available processors should therefore occasionally
poll
+         * this property and adjust their resource usage appropriately.
+         *
+         * @return the number of available processors.
+         */
+        static int availableProcessors();
+
     private:
 
         /**

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.cpp?rev=824956&r1=824955&r2=824956&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.cpp Tue Oct 13
22:24:15 2009
@@ -31,6 +31,12 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void SystemTest::test_availableProcessors() {
+
+    CPPUNIT_ASSERT( System::availableProcessors() >= 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void SystemTest::test_getenv() {
 
     CPPUNIT_ASSERT( System::getenv( "PATH" ) != "" );

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.h?rev=824956&r1=824955&r2=824956&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/SystemTest.h Tue Oct 13 22:24:15
2009
@@ -27,6 +27,7 @@
     class SystemTest : public CppUnit::TestFixture {
 
         CPPUNIT_TEST_SUITE( SystemTest );
+        CPPUNIT_TEST( test_availableProcessors );
         CPPUNIT_TEST( test_getenv );
         CPPUNIT_TEST( test_getenv2 );
         CPPUNIT_TEST( test_setenv );
@@ -40,6 +41,7 @@
         SystemTest();
         virtual ~SystemTest() {}
 
+        void test_availableProcessors();
         void test_getenv();
         void test_getenv2();
         void test_setenv();



Mime
View raw message