From a3ba93d9ce31c96570bf0b80ac9728ef98e93e77 Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Wed, 2 Feb 2011 21:52:43 +0000 Subject: Thread affinity on OS X and *BSD. Keep building the software plugin to prevent rot. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7045 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Thread.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'Source/Core/Common/Src/Thread.cpp') diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index 0238b14008..fe9586f427 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -19,6 +19,12 @@ #include "Thread.h" #include "Common.h" +#ifdef __APPLE__ +#include +#elif defined BSD4_4 +#include +#endif + #ifdef USE_BEGINTHREADEX #include #endif @@ -30,6 +36,8 @@ int CurrentThreadId() { #ifdef _WIN32 return GetCurrentThreadId(); +#elif defined __APPLE__ + return mach_thread_self(); #else return 0; #endif @@ -263,10 +271,12 @@ void SetCurrentThreadAffinity(u32 mask) #else // !WIN32, so must be POSIX threads -void LinuxSetThreadAffinity(pthread_t thread, u32 mask) -{ - // This is non-standard -#ifdef __linux__ +void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask) +{ +#ifdef __APPLE__ + thread_policy_set(pthread_mach_thread_np(thread), + THREAD_AFFINITY_POLICY, (integer_t *)&mask, 1); +#elif defined __linux__ || defined BSD4_4 cpu_set_t cpu_set; CPU_ZERO(&cpu_set); @@ -278,14 +288,9 @@ void LinuxSetThreadAffinity(pthread_t thread, u32 mask) #endif } -void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask) -{ - LinuxSetThreadAffinity(thread, mask); -} - void SetCurrentThreadAffinity(u32 mask) { - LinuxSetThreadAffinity(pthread_self(), mask); + SetThreadAffinity(pthread_self(), mask); } static pthread_key_t threadname_key; -- cgit v1.2.3