Fixed memory leaks in test suite
[libgit2.git] / src / thread-utils.c
blob5e8220f46ca2e7002bba745d8c0708622c64150f
1 #include "common.h"
2 #include "thread-utils.h"
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
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.
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
24 int git_online_cpus(void)
26 #ifdef _SC_NPROCESSORS_ONLN
27 long ncpus;
28 #endif
30 #ifdef _WIN32
31 SYSTEM_INFO info;
32 GetSystemInfo(&info);
34 if ((int)info.dwNumberOfProcessors > 0)
35 return (int)info.dwNumberOfProcessors;
36 #elif defined(hpux) || defined(__hpux) || defined(_hpux)
37 struct pst_dynamic psd;
39 if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
40 return (int)psd.psd_proc_cnt;
41 #endif
43 #ifdef _SC_NPROCESSORS_ONLN
44 if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
45 return (int)ncpus;
46 #endif
48 return 1;