// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. #pragma once #if PLATFORM_MAC #include "../Unix/UnixThread.h" #include /// /// Thread object for Mac platform. /// class MacThread : public UnixThread { public: /// /// Initializes a new instance of the class. /// /// The runnable. /// The thread name. /// The thread priority. MacThread(IRunnable* runnable, const String& name, ThreadPriority priority) : UnixThread(runnable, name, priority) { } public: /// /// Factory method to create a thread with the specified stack size and thread priority /// /// The runnable object to execute /// Name of the thread /// Tells the thread whether it needs to adjust its priority or not. Defaults to normal priority /// The size of the stack to create. 0 means use the current thread's stack size /// Pointer to the new thread or null if cannot create it static MacThread* Create(IRunnable* runnable, const String& name, ThreadPriority priority = ThreadPriority::Normal, uint32 stackSize = 0) { return (MacThread*)Setup(New(runnable, name, priority), stackSize); } protected: // [UnixThread] int32 GetThreadPriority(ThreadPriority priority) override { switch (priority) { case ThreadPriority::Highest: return 45; case ThreadPriority::AboveNormal: return 37; case ThreadPriority::Normal: return 31; case ThreadPriority::BelowNormal: return 25; case ThreadPriority::Lowest: return 20; } return 31; } int32 Start(pthread_attr_t& attr) override { return pthread_create(&_thread, &attr, ThreadProc, this); } void KillInternal(bool waitForJoin) override { if (waitForJoin) pthread_join(_thread, nullptr); pthread_kill(_thread, SIGKILL); } }; #endif