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