Compile fixes
- OSX and Windows compile fixes
This commit is contained in:
parent
5a681068fe
commit
0a8fdd7eff
|
@ -11,6 +11,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "openssl/sha.h"
|
#include "openssl/sha.h"
|
||||||
|
|
||||||
|
@ -23,7 +27,9 @@
|
||||||
#define EXPORT __declspec(dllexport)
|
#define EXPORT __declspec(dllexport)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
#define ntohll(x) ( ( (uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) | ntohl( ((unsigned int)(x >> 32)) ) )
|
#define ntohll(x) ( ( (uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) | ntohl( ((unsigned int)(x >> 32)) ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned long long max_val;
|
unsigned long long max_val;
|
||||||
unsigned char *initialHash;
|
unsigned char *initialHash;
|
||||||
|
@ -73,7 +79,7 @@ void getnumthreads()
|
||||||
int dwProcessAffinity = 0;
|
int dwProcessAffinity = 0;
|
||||||
int32_t core_count = 0;
|
int32_t core_count = 0;
|
||||||
#endif
|
#endif
|
||||||
unsigned int len = sizeof(dwProcessAffinity);
|
size_t len = sizeof(dwProcessAffinity);
|
||||||
if (numthreads > 0)
|
if (numthreads > 0)
|
||||||
return;
|
return;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -81,14 +87,16 @@ void getnumthreads()
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
sched_getaffinity(0, len, &dwProcessAffinity);
|
sched_getaffinity(0, len, &dwProcessAffinity);
|
||||||
#else
|
#else
|
||||||
if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0))
|
if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0) == 0)
|
||||||
numthreads = core_count;
|
numthreads = core_count;
|
||||||
#endif
|
#endif
|
||||||
for (unsigned int i = 0; i < len * 8; i++)
|
for (unsigned int i = 0; i < len * 8; i++)
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32)
|
||||||
if (dwProcessAffinity & (1i64 << i)) {
|
if (dwProcessAffinity & (1i64 << i)) {
|
||||||
#else
|
#elif defined __linux__
|
||||||
if (CPU_ISSET(i, &dwProcessAffinity)) {
|
if (CPU_ISSET(i, &dwProcessAffinity)) {
|
||||||
|
#else
|
||||||
|
if (dwProcessAffinity & (1 << i)) {
|
||||||
#endif
|
#endif
|
||||||
numthreads++;
|
numthreads++;
|
||||||
printf("Detected core on: %u\n", i);
|
printf("Detected core on: %u\n", i);
|
||||||
|
@ -107,11 +115,7 @@ extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, un
|
||||||
# else
|
# else
|
||||||
pthread_t* threads = (pthread_t*)calloc(sizeof(pthread_t), numthreads);
|
pthread_t* threads = (pthread_t*)calloc(sizeof(pthread_t), numthreads);
|
||||||
struct sched_param schparam;
|
struct sched_param schparam;
|
||||||
# ifdef __linux__
|
|
||||||
schparam.sched_priority = 0;
|
schparam.sched_priority = 0;
|
||||||
# else
|
|
||||||
schparam.sched_priority = PTHREAD_MIN_PRIORITY;
|
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
unsigned int *threaddata = (unsigned int *)calloc(sizeof(unsigned int), numthreads);
|
unsigned int *threaddata = (unsigned int *)calloc(sizeof(unsigned int), numthreads);
|
||||||
for (unsigned int i = 0; i < numthreads; i++) {
|
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__
|
# ifdef __linux__
|
||||||
pthread_setschedparam(threads[i], SCHED_IDLE, &schparam);
|
pthread_setschedparam(threads[i], SCHED_IDLE, &schparam);
|
||||||
# else
|
# else
|
||||||
pthread_setschedparam(threads[i], SCHED_RR, &schparam)
|
pthread_setschedparam(threads[i], SCHED_RR, &schparam);
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user