Fix windows builds (amend 0c4e0503)
[ardour.git] / libs / pbd / cpus.cc
index 0f73d51027012de4f1fd333a860be2399e886bbc..fed7725b766d819f33aef2148e3030edbc25a9db 100644 (file)
 #include "libpbd-config.h"
 #endif
 
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <unistd.h>
 #elif defined(__APPLE__) || defined(__FreeBSD__)
 #include <stddef.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
+#elif defined(PLATFORM_WINDOWS)
+#include <windows.h>
 #endif
 
 #include "pbd/cpus.h"
 uint32_t
 hardware_concurrency()
 {
+       if (getenv("CONCURRENCY")) {
+               int c = atoi (getenv("CONCURRENCY"));
+               if (c > 0) {
+                       return c;
+               }
+       }
 #if defined(PTW32_VERSION) || defined(__hpux)
-        return pthread_num_processors_np();
-#elif defined(__APPLE__) || defined(__FreeBSD__)
-        int count;
-        size_t size=sizeof(count);
-        return sysctlbyname("hw.physicalcpu",&count,&size,NULL,0)?0:count;
+       return pthread_num_processors_np();
+#elif defined(__APPLE__)
+       int count;
+       size_t size=sizeof(count);
+       return sysctlbyname("hw.physicalcpu",&count,&size,NULL,0)?0:count;
+#elif defined(__FreeBSD__)
+       int count;
+       size_t size=sizeof(count);
+       return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
 #elif defined(HAVE_UNISTD) && defined(_SC_NPROCESSORS_ONLN)
-        int const count=sysconf(_SC_NPROCESSORS_ONLN);
-        return (count>0)?count:0;
+       int const count=sysconf(_SC_NPROCESSORS_ONLN);
+       return (count>0)?count:0;
+#elif defined(PLATFORM_WINDOWS)
+       SYSTEM_INFO sys_info;
+       GetSystemInfo( &sys_info );
+       return sys_info.dwNumberOfProcessors;
 #else
-        return 0;
+       return 0;
 #endif
 }