More correct CPU affinity support for macOS.

This commit is contained in:
XMRig 2020-12-13 01:20:31 +07:00
parent 87fafcf91b
commit a36fb7e728
No known key found for this signature in database
GPG key ID: 446A53638BE94409
7 changed files with 50 additions and 42 deletions

View file

@ -26,6 +26,7 @@
#include <thread>
#ifndef XMRIG_OS_APPLE
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
@ -44,3 +45,4 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
}
#endif

View file

@ -19,8 +19,6 @@
#include <IOKit/IOKitLib.h>
#include <IOKit/ps/IOPowerSources.h>
#include <mach/thread_act.h>
#include <mach/thread_policy.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
@ -50,18 +48,10 @@ char *xmrig::Platform::createUserAgent()
}
#ifndef XMRIG_FEATURE_HWLOC
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
thread_port_t mach_thread;
thread_affinity_policy_data_t policy = { static_cast<integer_t>(cpu_id) };
mach_thread = pthread_mach_thread_np(pthread_self());
const bool result = (thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1) == KERN_SUCCESS);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
return true;
}
#endif
void xmrig::Platform::setProcessPriority(int)