31 memset(&info, 0,
sizeof(info));
33 if (info.dwNumberOfProcessors >= 1 && info.dwNumberOfProcessors < INT_MAX)
34 return (
int)info.dwNumberOfProcessors;
37 #elif defined(HAVE_SYSCONF)
38 #ifdef _SC_NPROCESSORS_CONF
39 long cpus_conf = sysconf(_SC_NPROCESSORS_CONF);
43 #ifdef _SC_NPROCESSORS_ONLN
44 long cpus_onln = sysconf(_SC_NPROCESSORS_ONLN);
50 if (cpus_conf > 0 && cpus_onln < 0) {
52 }
else if (cpus_onln > 0 && cpus_conf < 0) {
54 }
else if (cpus_onln > 0 && cpus_conf > 0) {
55 if (cpus_onln < cpus_conf) {
56 log_notice(
LD_GENERAL,
"I think we have %ld CPUS, but only %ld of them "
57 "are available. Telling Tor to only use %ld. You can over"
58 "ride this with the NumCPUs option",
59 cpus_conf, cpus_onln, cpus_onln);
64 if (cpus >= 1 && cpus < INT_MAX)
73 #define MAX_DETECTABLE_CPUS 16
83 static int num_cpus = -2;
87 if (num_cpus > MAX_DETECTABLE_CPUS) {
89 log_notice(
LD_GENERAL,
"Wow! I detected that you have %d CPUs. I "
90 "will not autodetect any more than %d, though. If you "
91 "want to configure more, set NumCPUs in your torrc",
92 num_cpus, MAX_DETECTABLE_CPUS);
93 num_cpus = MAX_DETECTABLE_CPUS;
static int compute_num_cpus_impl(void)
int compute_num_cpus(void)
Macros to manage assertions, fatal and non-fatal.