diff --git a/Source/Engine/Platform/Apple/ApplePlatform.cpp b/Source/Engine/Platform/Apple/ApplePlatform.cpp index d4348b107..c7ab4424d 100644 --- a/Source/Engine/Platform/Apple/ApplePlatform.cpp +++ b/Source/Engine/Platform/Apple/ApplePlatform.cpp @@ -19,6 +19,7 @@ #include "Engine/Platform/StringUtils.h" #include "Engine/Platform/WindowsManager.h" #include "Engine/Platform/Clipboard.h" +#include "Engine/Platform/Thread.h" #include "Engine/Platform/IGuiData.h" #include "Engine/Platform/Base/PlatformUtils.h" #include "Engine/Utilities/StringConverter.h" @@ -176,12 +177,19 @@ uint64 ApplePlatform::GetCurrentThreadID() void ApplePlatform::SetThreadPriority(ThreadPriority priority) { - // TODO: impl this + struct sched_param sched; + Platform::MemoryClear(&sched, sizeof(struct sched_param)); + int32 policy = SCHED_RR; + pthread_getschedparam(pthread_self(), &policy, &sched); + sched.sched_priority = AppleThread::GetAppleThreadPriority(priority); + pthread_setschedparam(pthread_self(), policy, &sched); } void ApplePlatform::SetThreadAffinityMask(uint64 affinityMask) { - // TODO: impl this + thread_affinity_policy policy; + policy.affinity_tag = affinityMask; + thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_AFFINITY_POLICY, (integer_t*)&policy, THREAD_AFFINITY_POLICY_COUNT); } void ApplePlatform::Sleep(int32 milliseconds) diff --git a/Source/Engine/Platform/Apple/AppleThread.h b/Source/Engine/Platform/Apple/AppleThread.h index 43d9d2966..a578092b6 100644 --- a/Source/Engine/Platform/Apple/AppleThread.h +++ b/Source/Engine/Platform/Apple/AppleThread.h @@ -40,10 +40,7 @@ public: return (AppleThread*)Setup(New(runnable, name, priority), stackSize); } -protected: - - // [UnixThread] - int32 GetThreadPriority(ThreadPriority priority) override + static int32 GetAppleThreadPriority(ThreadPriority priority) { switch (priority) { @@ -60,6 +57,14 @@ protected: } return 31; } + +protected: + + // [UnixThread] + int32 GetThreadPriority(ThreadPriority priority) override + { + return GetAppleThreadPriority(priority); + } int32 Start(pthread_attr_t& attr) override { return pthread_create(&_thread, &attr, ThreadProc, this); diff --git a/Source/Engine/Platform/Unix/UnixThread.cpp b/Source/Engine/Platform/Unix/UnixThread.cpp index f662bdba8..29dc5f881 100644 --- a/Source/Engine/Platform/Unix/UnixThread.cpp +++ b/Source/Engine/Platform/Unix/UnixThread.cpp @@ -26,6 +26,12 @@ int32 UnixThread::Start(pthread_attr_t& attr) void* UnixThread::ThreadProc(void* pThis) { auto thread = (UnixThread*)pThis; +#if PLATFORM_APPLE_FAMILY + // Apple doesn't support creating named thread so assign name here + { + pthread_setname_np(StringAnsi(thread->GetName()).Get()); + } +#endif const int32 exitCode = thread->Run(); return (void*)(uintptr)exitCode; }