source src/thread-utils.c
Line | Flow | Count | Block(s) | Source |
---|---|---|---|---|
1 | - | /* | ||
2 | - | * Copyright (C) the libgit2 contributors. All rights reserved. | ||
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 | - | */ | ||
7 | - | |||
8 | - | #include "common.h" | ||
9 | - | #include "thread-utils.h" | ||
10 | - | |||
11 | - | #ifdef _WIN32 | ||
12 | - | #ifndef WIN32_LEAN_AND_MEAN | ||
13 | - | # define WIN32_LEAN_AND_MEAN | ||
14 | - | #endif | ||
15 | - | # include <windows.h> | ||
16 | - | #elif defined(hpux) || defined(__hpux) || defined(_hpux) | ||
17 | - | # include <sys/pstat.h> | ||
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 | ||
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 | ||
31 | - | #endif | ||
32 | - | |||
33 | 36 | 2 | 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 | 36 | 2,3 | if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0) | |
54 | 36 | 4 | return (int)ncpus; | |
55 | - | #endif | ||
56 | - | |||
57 | ##### | 5 | return 1; | |
58 | - | } |