From 9e2389306b68d8c47c5218a994338ed0c797e21b Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Tue, 24 May 2016 09:42:49 +0200 Subject: [PATCH] BSD compile fixes - bitmsghash should now build and run on BSD (thanks for FreeBSD/Dragonfly maintainers for assistance) - if it cannot detect the number of cores, will default to one thread (previously it broke) --- src/bitmsghash/bitmsghash.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bitmsghash/bitmsghash.cpp b/src/bitmsghash/bitmsghash.cpp index 4862c341..f4979702 100644 --- a/src/bitmsghash/bitmsghash.cpp +++ b/src/bitmsghash/bitmsghash.cpp @@ -11,7 +11,7 @@ #include #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FreeBSD__) || defined (__DragonFly__) || defined (__OpenBSD__) || defined (__NetBSD__) #include #include #endif @@ -89,18 +89,20 @@ void getnumthreads() #else if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0) == 0) numthreads = core_count; + else if (sysctlbyname("hw.ncpu", &core_count, &len, 0, 0) == 0) + numthreads = core_count; #endif for (unsigned int i = 0; i < len * 8; i++) #if defined(_WIN32) - if (dwProcessAffinity & (1i64 << i)) { + if (dwProcessAffinity & (1i64 << i)) #elif defined __linux__ - if (CPU_ISSET(i, &dwProcessAffinity)) { + if (CPU_ISSET(i, &dwProcessAffinity)) #else - if (dwProcessAffinity & (1 << i)) { + if (dwProcessAffinity & (1 << i)) #endif numthreads++; - printf("Detected core on: %u\n", i); - } + if (numthreads == 0) // something failed + numthreads = 1; printf("Number of threads: %i\n", (int)numthreads); }