line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 |
16
|
|
|
|
|
|
|
#elif defined(hpux) || defined(__hpux) || defined(_hpux) |
17
|
|
|
|
|
|
|
# include |
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
|
0
|
|
|
|
|
|
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
|
0
|
0
|
|
|
|
|
if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0) |
54
|
0
|
|
|
|
|
|
return (int)ncpus; |
55
|
|
|
|
|
|
|
#endif |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return 1; |
58
|
|
|
|
|
|
|
} |