platform.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00025 #include "platform.h"
00026 
00027 
00028 #ifdef _WIN32
00029 #include "vigra/windows.h"
00030 #elif defined(sun) || defined(__sun) || defined(__sun__)
00031 #include <unistd.h>
00032 #else
00033 #include <unistd.h>
00034 #include <sys/sysctl.h>
00035 #endif
00036 
00037 namespace hugin_utils {
00038     
00039 #ifdef _WIN32
00040 
00041 int getCPUCount()
00042 {
00043     SYSTEM_INFO si;
00044     GetSystemInfo(&si);
00045     return si.dwNumberOfProcessors;
00046 }
00047 
00048 #else
00049 
00050 int getCPUCount()
00051 {
00052     #ifdef HW_NCPU
00053         // BSD and OSX like system
00054         int mib[2];
00055         int numCPUs = 1;
00056         size_t len = sizeof(numCPUs);
00057 
00058         mib[0] = CTL_HW;
00059         mib[1] = HW_NCPU;
00060         sysctl(mib, 2, &numCPUs, &len, 0, 0);
00061         return numCPUs;
00062         
00063     #elif defined(_SC_NPROCESSORS_ONLN)
00064         // Linux and Solaris
00065         long nProcessorsOnline = sysconf(_SC_NPROCESSORS_ONLN);
00066         return nProcessorsOnline;
00067     #else
00068         #warning sysconf or sysctl does not support quering the number of processors/cores.
00069         return -1;
00070     #endif
00071 }
00072 
00073 #endif
00074 
00075 } //namespace

Generated on 28 Nov 2014 for Hugintrunk by  doxygen 1.4.7