]>
Commit | Line | Data |
---|---|---|
64a47c01 | 1 | #include "common.h" |
36f0f61f AE |
2 | #include "thread-utils.h" |
3 | ||
4 | #ifdef _WIN32 | |
5 | # define WIN32_LEAN_AND_MEAN | |
6 | # include <windows.h> | |
7 | #elif defined(hpux) || defined(__hpux) || defined(_hpux) | |
8 | # include <sys/pstat.h> | |
9 | #endif | |
10 | ||
11 | /* | |
12 | * By doing this in two steps we can at least get | |
13 | * the function to be somewhat coherent, even | |
14 | * with this disgusting nest of #ifdefs. | |
15 | */ | |
16 | #ifndef _SC_NPROCESSORS_ONLN | |
17 | # ifdef _SC_NPROC_ONLN | |
18 | # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN | |
19 | # elif defined _SC_CRAY_NCPU | |
20 | # define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU | |
21 | # endif | |
22 | #endif | |
23 | ||
24 | int git_online_cpus(void) | |
25 | { | |
26 | #ifdef _SC_NPROCESSORS_ONLN | |
27 | long ncpus; | |
28 | #endif | |
29 | ||
30 | #ifdef _WIN32 | |
31 | SYSTEM_INFO info; | |
32 | GetSystemInfo(&info); | |
33 | ||
34 | if ((int)info.dwNumberOfProcessors > 0) | |
35 | return (int)info.dwNumberOfProcessors; | |
36 | #elif defined(hpux) || defined(__hpux) || defined(_hpux) | |
37 | struct pst_dynamic psd; | |
38 | ||
39 | if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0)) | |
40 | return (int)psd.psd_proc_cnt; | |
41 | #endif | |
42 | ||
43 | #ifdef _SC_NPROCESSORS_ONLN | |
44 | if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0) | |
45 | return (int)ncpus; | |
46 | #endif | |
47 | ||
48 | return 1; | |
49 | } |