2008-02-23 10:11:56 +08:00
|
|
|
#include "cache.h"
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 15:51:05 +08:00
|
|
|
#include "thread-utils.h"
|
2008-02-23 10:11:56 +08:00
|
|
|
|
2009-09-16 16:20:26 +08:00
|
|
|
#if defined(hpux) || defined(__hpux) || defined(_hpux)
|
2008-02-23 10:11:56 +08:00
|
|
|
# include <sys/pstat.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* By doing this in two steps we can at least get
|
|
|
|
* the function to be somewhat coherent, even
|
|
|
|
* with this disgusting nest of #ifdefs.
|
|
|
|
*/
|
|
|
|
#ifndef _SC_NPROCESSORS_ONLN
|
|
|
|
# ifdef _SC_NPROC_ONLN
|
|
|
|
# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
|
|
|
|
# elif defined _SC_CRAY_NCPU
|
|
|
|
# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int online_cpus(void)
|
|
|
|
{
|
|
|
|
#ifdef _SC_NPROCESSORS_ONLN
|
|
|
|
long ncpus;
|
|
|
|
#endif
|
|
|
|
|
2013-05-03 03:26:08 +08:00
|
|
|
#ifdef GIT_WINDOWS_NATIVE
|
2008-02-23 10:11:56 +08:00
|
|
|
SYSTEM_INFO info;
|
|
|
|
GetSystemInfo(&info);
|
|
|
|
|
|
|
|
if ((int)info.dwNumberOfProcessors > 0)
|
|
|
|
return (int)info.dwNumberOfProcessors;
|
|
|
|
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
|
|
|
|
struct pst_dynamic psd;
|
|
|
|
|
|
|
|
if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
|
|
|
|
return (int)psd.psd_proc_cnt;
|
2015-03-08 15:14:37 +08:00
|
|
|
#elif defined(HAVE_BSD_SYSCTL) && defined(HW_NCPU)
|
|
|
|
int mib[2];
|
|
|
|
size_t len;
|
|
|
|
int cpucount;
|
|
|
|
|
|
|
|
mib[0] = CTL_HW;
|
|
|
|
# ifdef HW_AVAILCPU
|
|
|
|
mib[1] = HW_AVAILCPU;
|
|
|
|
len = sizeof(cpucount);
|
|
|
|
if (!sysctl(mib, 2, &cpucount, &len, NULL, 0))
|
|
|
|
return cpucount;
|
|
|
|
# endif /* HW_AVAILCPU */
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
len = sizeof(cpucount);
|
|
|
|
if (!sysctl(mib, 2, &cpucount, &len, NULL, 0))
|
|
|
|
return cpucount;
|
|
|
|
#endif /* defined(HAVE_BSD_SYSCTL) && defined(HW_NCPU) */
|
2008-02-23 10:11:56 +08:00
|
|
|
|
|
|
|
#ifdef _SC_NPROCESSORS_ONLN
|
|
|
|
if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
|
|
|
|
return (int)ncpus;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2010-04-08 15:15:39 +08:00
|
|
|
|
|
|
|
int init_recursive_mutex(pthread_mutex_t *m)
|
|
|
|
{
|
|
|
|
pthread_mutexattr_t a;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pthread_mutexattr_init(&a);
|
|
|
|
if (!ret) {
|
|
|
|
ret = pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
if (!ret)
|
|
|
|
ret = pthread_mutex_init(m, &a);
|
|
|
|
pthread_mutexattr_destroy(&a);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|