From 29f0f9bc18d3981b622b9c91a69aa597189eafb8 Mon Sep 17 00:00:00 2001 From: Znort 987 Date: Mon, 15 Aug 2011 11:55:12 +0200 Subject: [PATCH] Properly detect number of cores on WIN32 --- main.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index e4ee84e3..fb072fe8 100644 --- a/main.c +++ b/main.c @@ -4165,12 +4165,34 @@ int main (int argc, char *argv[]) if (unlikely(!current_hash)) quit (1, "main OOM"); -#ifdef WIN32 - opt_n_threads = num_processors = 1; -#else - num_processors = sysconf(_SC_NPROCESSORS_ONLN); + // Reckon number of cores in the box + #if defined(WIN32) + + DWORD system_am; + DWORD process_am; + BOOL ok = GetProcessAffinityMask( + GetCurrentProcess(), + &system_am, + &process_am + ); + if (!ok) { + applog(LOG_ERR, "couldn't figure out number of processors :("); + num_processors = 1; + } else { + size_t n = 32; + num_processors = 0; + while (n--) + if (process_am & (1<