builtin-mailinfo.c: check error status from rewind and ftruncate
[git/spearce.git] / thread-utils.c
blob4f9c829c2df319e386b6b5d4f5c23818cc21c979
1 #include "cache.h"
3 #if defined(hpux) || defined(__hpux) || defined(_hpux)
4 # include <sys/pstat.h>
5 #endif
7 /*
8 * By doing this in two steps we can at least get
9 * the function to be somewhat coherent, even
10 * with this disgusting nest of #ifdefs.
12 #ifndef _SC_NPROCESSORS_ONLN
13 # ifdef _SC_NPROC_ONLN
14 # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
15 # elif defined _SC_CRAY_NCPU
16 # define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
17 # endif
18 #endif
20 int online_cpus(void)
22 #ifdef _SC_NPROCESSORS_ONLN
23 long ncpus;
24 #endif
26 #ifdef _WIN32
27 SYSTEM_INFO info;
28 GetSystemInfo(&info);
30 if ((int)info.dwNumberOfProcessors > 0)
31 return (int)info.dwNumberOfProcessors;
32 #elif defined(hpux) || defined(__hpux) || defined(_hpux)
33 struct pst_dynamic psd;
35 if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
36 return (int)psd.psd_proc_cnt;
37 #endif
39 #ifdef _SC_NPROCESSORS_ONLN
40 if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
41 return (int)ncpus;
42 #endif
44 return 1;