You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2007/07/11 02:33:23 UTC
svn commit: r555125 - /incubator/stdcxx/trunk/tests/src/thread.cpp
Author: sebor
Date: Tue Jul 10 17:33:22 2007
New Revision: 555125
URL: http://svn.apache.org/viewvc?view=rev&rev=555125
Log:
2007-07-10 Martin Sebor <se...@roguewave.com>
* thread.cpp (rw_get_cpus): Used sysconf() to try to determine
the number of processors programmatically for efficiency before
invoking a shell script to read system files.
Modified:
incubator/stdcxx/trunk/tests/src/thread.cpp
Modified: incubator/stdcxx/trunk/tests/src/thread.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/thread.cpp?view=diff&rev=555125&r1=555124&r2=555125
==============================================================================
--- incubator/stdcxx/trunk/tests/src/thread.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/thread.cpp Tue Jul 10 17:33:22 2007
@@ -35,6 +35,7 @@
#ifndef _WIN32
# include <stdio.h> // for FILE, fscanf(), popen()
+# include <unistd.h> // for sysconf(), _SC_NPROCESSORS_{CONF,ONLN}
#else // _WIN32
# include <windows.h> // for GetSystemInfo()
#endif // _WIN32
@@ -424,8 +425,25 @@
int ncpus = -1;
- if (cmd) {
- // open and read the output of the command from a pipe
+# ifdef _SC_NPROCESSORS_ONLN
+ // try to obtain the number of processors that are currently online
+ // programmatically and fall back on the shell script above if it
+ // fails
+ ncpus = int (sysconf (_SC_NPROCESSORS_CONF));
+
+# elif defined (_SC_NPROCESSORS_CONF)
+
+ // try to obtain the number of processors the system is configured
+ // with (not all of them are necessarily online) programmatically
+ // and fall back on the shell script above if it fails
+ ncpus = int (sysconf (_SC_NPROCESSORS_CONF));
+
+# endif // _SC_NPROCESSORS_CONF
+
+ if (ncpus < 1 && cmd) {
+ // if the number of processors couldn't be determined using
+ // sysconf() above, open and read the output of the command
+ // from a pipe
FILE* const fp = popen (cmd, "r");
if (fp) {