From 222c0e0fc59c2971668972ecf96ecf2e02ad399c Mon Sep 17 00:00:00 2001 From: scribam Date: Sun, 19 Nov 2017 23:02:35 +0100 Subject: [PATCH] Fix set thread affinity on OS X (#3757) --- Utilities/Thread.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index d75c1b03f7..a6159b1f78 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -16,6 +16,8 @@ #ifdef __APPLE__ #define _XOPEN_SOURCE #define __USE_GNU +#include +#include #endif #include #include @@ -1916,6 +1918,10 @@ void thread_ctrl::set_ideal_processor_core(int core) #ifdef _WIN32 HANDLE _this_thread = GetCurrentThread(); SetThreadIdealProcessor(_this_thread, core); +#elif __APPLE__ + thread_affinity_policy_data_t policy = { static_cast(core) }; + thread_port_t mach_thread = pthread_mach_thread_np(pthread_self()); + thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1); #else cpu_set_t cs; CPU_ZERO(&cs);