// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#if PLATFORM_WIN32
#include "Engine/Platform/Base/ThreadBase.h"
///
/// Thread object for Win32 platform.
///
class FLAXENGINE_API Win32Thread : public ThreadBase
{
private:
void* _thread;
public:
Win32Thread(IRunnable* runnable, const String& name, ThreadPriority priority);
///
/// Finalizes an instance of the class.
///
~Win32Thread();
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 Win32Thread* Create(IRunnable* runnable, const String& name, ThreadPriority priority = ThreadPriority::Normal, uint32 stackSize = 0);
void* GetHandle() const
{
return _thread;
}
private:
bool Start(uint32 stackSize);
static unsigned long ThreadProc(void* pThis);
public:
// [ThreadBase]
void Join() override;
protected:
// [ThreadBase]
void ClearHandleInternal() override;
void SetPriorityInternal(ThreadPriority priority) override;
void KillInternal(bool waitForJoin) override;
};
#endif