Skip to content
This repository has been archived by the owner on Sep 22, 2018. It is now read-only.

Commit

Permalink
Official MAC build step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
fireice-uk committed Mar 17, 2017
1 parent 7494138 commit d4d3048
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
endif()

find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})

#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CONFIGURATION_TYPES "RELEASE;STATIC")
Expand Down
18 changes: 18 additions & 0 deletions minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
#else
#include <pthread.h>

#if defined(__APPLE__)
#include <mach/thread_policy.h>
#include <mach/thread_act.h>
#define SYSCTL_CORE_COUNT "machdep.cpu.core_count"
#endif

void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
{
#if defined(__APPLE__)
thread_port_t mach_thread;
thread_affinity_policy_data_t policy = { cpu_id };
mach_thread = pthread_mach_thread_np(h);
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1);
#else
cpu_set_t mn;
CPU_ZERO(&mn);
CPU_SET(cpu_id, &mn);
pthread_setaffinity_np(h, sizeof(cpu_set_t), &mn);
#endif
}
#endif // _WIN32

Expand Down Expand Up @@ -297,7 +310,12 @@ std::vector<minethd*>* minethd::thread_starter(miner_work& pWork)
minethd* thd = new minethd(pWork, i, cfg.bDoubleMode, cfg.bNoPrefetch);

if(cfg.iCpuAff >= 0)
{
#if defined(__APPLE__)
printer::inst()->print_msg(L1, "WARNING on MacOS thread affinity is only advisory."
#endif
thd_setaffinity(thd->oWorkThd.native_handle(), cfg.iCpuAff);
}

pvThreads->push_back(thd);

Expand Down
1 change: 1 addition & 0 deletions msgstruct.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <string>
#include <string.h>
#include <assert.h>

Expand Down
5 changes: 5 additions & 0 deletions socks.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ inline void sock_close(SOCKET s)
inline const char* sock_strerror(char* buf, size_t len)
{
buf[0] = '\0';
#if defined(__APPLE__)
strerror_r(errno, buf, len);
return buf;
#else
return strerror_r(errno, buf, len);
#endif
}

inline const char* sock_gai_strerror(int err, char* buf, size_t len)
Expand Down

0 comments on commit d4d3048

Please sign in to comment.