Merge branch 'maint-1.6.0' into maint-1.6.1
[git/spearce.git] / thread-utils.c
blob55e7e2904eb5f95cedaec2520ddd1d158ee93c7a
1 #include "cache.h"
3 #ifdef _WIN32
4 # define WIN32_LEAN_AND_MEAN
5 # include <windows.h>
6 #elif defined(hpux) || defined(__hpux) || defined(_hpux)
7 # include <sys/pstat.h>
8 #endif
11 * By doing this in two steps we can at least get
12 * the function to be somewhat coherent, even
13 * with this disgusting nest of #ifdefs.
15 #ifndef _SC_NPROCESSORS_ONLN
16 # ifdef _SC_NPROC_ONLN
17 # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
18 # elif defined _SC_CRAY_NCPU
19 # define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
20 # endif
21 #endif
23 int online_cpus(void)
25 #ifdef _SC_NPROCESSORS_ONLN
26 long ncpus;
27 #endif
29 #ifdef _WIN32
30 SYSTEM_INFO info;
31 GetSystemInfo(&info);
33 if ((int)info.dwNumberOfProcessors > 0)
34 return (int)info.dwNumberOfProcessors;
35 #elif defined(hpux) || defined(__hpux) || defined(_hpux)
36 struct pst_dynamic psd;
38 if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
39 return (int)psd.psd_proc_cnt;
40 #endif
42 #ifdef _SC_NPROCESSORS_ONLN
43 if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
44 return (int)ncpus;
45 #endif
47 return 1;