Having DSS compiles on Solaris 10 [part 4]
juil 6th, 2007 by Prune
Will this stop one day ?
I just came with a new patch which keeps the dynamic stuff of the “uname -X” trick but use a simple library to check the number of CPU. Low cost and efficency guarantied.
This code was submited by Fabrice Aneche which is a better coder than I am and who took the time to dig this out while I was drinking wine and eating french cheese
This patch can be used like :
patch -p 1 < patch-dss.diff --- OS.cpp Fri Jul 6 17:33:39 2007 +++ OS.cpp.prune Fri Jul 6 17:32:07 2007 @@ -69,10 +69,14 @@ #include <sys/sysctl.h> #endif -#if (__solaris__ || __linux__ || __linuxppc__) +#if (__linux__ || __linuxppc__) #include "StringParser.h" #endif +#if (__solaris__) + #include <unistd.h> +#endif + #if __sgi__ #include <sys/systeminfo.h> #endif @@ -410,37 +414,8 @@ #if(__solaris__) { UInt32 numCPUs = 0; - char linebuff[512] = ""; - StrPtrLen line(linebuff, sizeof(linebuff)); - StrPtrLen word; - - FILE *p = ::popen("uname -X","r"); - while((::fgets(linebuff, sizeof(linebuff -1), p)) > 0) - { - StringParser lineParser(&line); - lineParser.ConsumeWhitespace(); //skip over leading whitespace - - if (lineParser.GetDataRemaining() == 0) // must be an empty line - continue; - - lineParser.ConsumeUntilWhitespace(&word); - - if ( word.Equal("NumCPU")) // found a tag as first word in line - { - lineParser.GetThru(NULL,'='); - lineParser.ConsumeWhitespace(); //skip over leading whitespace - lineParser.ConsumeUntilWhitespace(&word); //read the number of cpus - if (word.Len > 0) - ::sscanf(word.Ptr, "%lu", &numCPUs); - - break; - } - } - if (numCPUs == 0) - numCPUs = 1; - - ::pclose(p); + numCPUs = sysconf(_SC_NPROCESSORS_ONLN); return numCPUs; } #endif