From 0a8fdd7effc98f5e808935b5d3df2b1714558c71 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Sun, 8 Nov 2015 11:26:17 +0100 Subject: [PATCH] Compile fixes - OSX and Windows compile fixes --- src/bitmsghash/bitmsghash.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bitmsghash/bitmsghash.cpp b/src/bitmsghash/bitmsghash.cpp index e05c88ae..4862c341 100644 --- a/src/bitmsghash/bitmsghash.cpp +++ b/src/bitmsghash/bitmsghash.cpp @@ -11,6 +11,10 @@ #include #include #include +#ifdef __APPLE__ +#include +#include +#endif #include "openssl/sha.h" @@ -23,7 +27,9 @@ #define EXPORT __declspec(dllexport) #endif +#ifndef __APPLE__ #define ntohll(x) ( ( (uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) | ntohl( ((unsigned int)(x >> 32)) ) ) +#endif unsigned long long max_val; unsigned char *initialHash; @@ -73,7 +79,7 @@ void getnumthreads() int dwProcessAffinity = 0; int32_t core_count = 0; #endif - unsigned int len = sizeof(dwProcessAffinity); + size_t len = sizeof(dwProcessAffinity); if (numthreads > 0) return; #ifdef _WIN32 @@ -81,14 +87,16 @@ void getnumthreads() #elif __linux__ sched_getaffinity(0, len, &dwProcessAffinity); #else - if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0)) + if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0) == 0) numthreads = core_count; #endif for (unsigned int i = 0; i < len * 8; i++) -#ifdef _WIN32 +#if defined(_WIN32) if (dwProcessAffinity & (1i64 << i)) { -#else +#elif defined __linux__ if (CPU_ISSET(i, &dwProcessAffinity)) { +#else + if (dwProcessAffinity & (1 << i)) { #endif numthreads++; printf("Detected core on: %u\n", i); @@ -107,11 +115,7 @@ extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, un # else pthread_t* threads = (pthread_t*)calloc(sizeof(pthread_t), numthreads); struct sched_param schparam; -# ifdef __linux__ schparam.sched_priority = 0; -# else - schparam.sched_priority = PTHREAD_MIN_PRIORITY; -# endif # endif unsigned int *threaddata = (unsigned int *)calloc(sizeof(unsigned int), numthreads); for (unsigned int i = 0; i < numthreads; i++) { @@ -124,7 +128,7 @@ extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, un # ifdef __linux__ pthread_setschedparam(threads[i], SCHED_IDLE, &schparam); # else - pthread_setschedparam(threads[i], SCHED_RR, &schparam) + pthread_setschedparam(threads[i], SCHED_RR, &schparam); # endif # endif }