]> git.proxmox.com Git - libgit2.git/blame - src/thread-utils.c
Include stacktrace summary in memory leak output.
[libgit2.git] / src / thread-utils.c
CommitLineData
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 */
64a47c01 7#include "common.h"
36f0f61f
AE
8#include "thread-utils.h"
9
10#ifdef _WIN32
87d9869f
VM
11# define WIN32_LEAN_AND_MEAN
12# include <windows.h>
36f0f61f 13#elif defined(hpux) || defined(__hpux) || defined(_hpux)
87d9869f 14# include <sys/pstat.h>
36f0f61f
AE
15#endif
16
17/*
18 * By doing this in two steps we can at least get
19 * the function to be somewhat coherent, even
20 * with this disgusting nest of #ifdefs.
21 */
22#ifndef _SC_NPROCESSORS_ONLN
87d9869f
VM
23# ifdef _SC_NPROC_ONLN
24# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
25# elif defined _SC_CRAY_NCPU
26# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
27# endif
36f0f61f
AE
28#endif
29
30int git_online_cpus(void)
31{
32#ifdef _SC_NPROCESSORS_ONLN
33 long ncpus;
34#endif
35
36#ifdef _WIN32
37 SYSTEM_INFO info;
38 GetSystemInfo(&info);
39
40 if ((int)info.dwNumberOfProcessors > 0)
41 return (int)info.dwNumberOfProcessors;
42#elif defined(hpux) || defined(__hpux) || defined(_hpux)
43 struct pst_dynamic psd;
44
45 if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
46 return (int)psd.psd_proc_cnt;
47#endif
48
49#ifdef _SC_NPROCESSORS_ONLN
50 if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
51 return (int)ncpus;
52#endif
53
54 return 1;
55}