]>
Commit | Line | Data |
---|---|---|
bb742ede | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
bb742ede VM |
3 | * |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
eae0bfdc | 7 | |
64a47c01 | 8 | #include "common.h" |
36f0f61f AE |
9 | #include "thread-utils.h" |
10 | ||
11 | #ifdef _WIN32 | |
2563101b | 12 | #ifndef WIN32_LEAN_AND_MEAN |
87d9869f | 13 | # define WIN32_LEAN_AND_MEAN |
2563101b | 14 | #endif |
87d9869f | 15 | # include <windows.h> |
36f0f61f | 16 | #elif defined(hpux) || defined(__hpux) || defined(_hpux) |
87d9869f | 17 | # include <sys/pstat.h> |
36f0f61f AE |
18 | #endif |
19 | ||
20 | /* | |
21 | * By doing this in two steps we can at least get | |
22 | * the function to be somewhat coherent, even | |
23 | * with this disgusting nest of #ifdefs. | |
24 | */ | |
25 | #ifndef _SC_NPROCESSORS_ONLN | |
87d9869f VM |
26 | # ifdef _SC_NPROC_ONLN |
27 | # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN | |
28 | # elif defined _SC_CRAY_NCPU | |
29 | # define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU | |
30 | # endif | |
36f0f61f AE |
31 | #endif |
32 | ||
33 | int git_online_cpus(void) | |
34 | { | |
35 | #ifdef _SC_NPROCESSORS_ONLN | |
36 | long ncpus; | |
37 | #endif | |
38 | ||
39 | #ifdef _WIN32 | |
40 | SYSTEM_INFO info; | |
41 | GetSystemInfo(&info); | |
42 | ||
43 | if ((int)info.dwNumberOfProcessors > 0) | |
44 | return (int)info.dwNumberOfProcessors; | |
45 | #elif defined(hpux) || defined(__hpux) || defined(_hpux) | |
46 | struct pst_dynamic psd; | |
47 | ||
48 | if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0)) | |
49 | return (int)psd.psd_proc_cnt; | |
50 | #endif | |
51 | ||
52 | #ifdef _SC_NPROCESSORS_ONLN | |
53 | if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0) | |
54 | return (int)ncpus; | |
55 | #endif | |
56 | ||
57 | return 1; | |
58 | } |