// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. #pragma once #if PLATFORM_LINUX #include "../Unix/UnixThread.h" #include /// /// Thread object for Linux platform. /// class LinuxThread : public UnixThread { public: /// /// Initializes a new instance of the class. /// /// The runnable. /// The thread name. /// The thread priority. LinuxThread(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 LinuxThread* Create(IRunnable* runnable, const String& name, ThreadPriority priority = ThreadPriority::Normal, uint32 stackSize = 0) { return (LinuxThread*)Setup(New(runnable, name, priority), stackSize); } protected: // [UnixThread] int32 Start(pthread_attr_t& attr) override { const int result = pthread_create(&_thread, &attr, ThreadProc, this); if (result != 0) pthread_setname_np(_thread, _name.ToStringAnsi().Get()); return result; } void KillInternal(bool waitForJoin) override { if (waitForJoin) pthread_join(_thread, nullptr); pthread_kill(_thread, SIGKILL); } }; #endif