Skip to content

Commit d4d3048

Browse files
committed
Official MAC build step 1
1 parent 7494138 commit d4d3048

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
1414
endif()
1515

1616
find_package(OpenSSL REQUIRED)
17+
include_directories(${OPENSSL_INCLUDE_DIR})
1718

1819
#set(CMAKE_VERBOSE_MAKEFILE ON)
1920
set(CMAKE_CONFIGURATION_TYPES "RELEASE;STATIC")

minethd.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,25 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
3737
#else
3838
#include <pthread.h>
3939

40+
#if defined(__APPLE__)
41+
#include <mach/thread_policy.h>
42+
#include <mach/thread_act.h>
43+
#define SYSCTL_CORE_COUNT "machdep.cpu.core_count"
44+
#endif
45+
4046
void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
4147
{
48+
#if defined(__APPLE__)
49+
thread_port_t mach_thread;
50+
thread_affinity_policy_data_t policy = { cpu_id };
51+
mach_thread = pthread_mach_thread_np(h);
52+
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1);
53+
#else
4254
cpu_set_t mn;
4355
CPU_ZERO(&mn);
4456
CPU_SET(cpu_id, &mn);
4557
pthread_setaffinity_np(h, sizeof(cpu_set_t), &mn);
58+
#endif
4659
}
4760
#endif // _WIN32
4861

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

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

302320
pvThreads->push_back(thd);
303321

msgstruct.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <string>
23
#include <string.h>
34
#include <assert.h>
45

socks.h

+5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ inline void sock_close(SOCKET s)
7676
inline const char* sock_strerror(char* buf, size_t len)
7777
{
7878
buf[0] = '\0';
79+
#if defined(__APPLE__)
80+
strerror_r(errno, buf, len);
81+
return buf;
82+
#else
7983
return strerror_r(errno, buf, len);
84+
#endif
8085
}
8186

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

0 commit comments

Comments
 (0)