Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildAccelerator/Common/Public/UbaThread.h
henrik karlsson 9775455aca [UBA]
* Fixed bug in Thread code where two concurrent waits could race and cause delete of functor at the same time

[CL 34081099 by henrik karlsson in ue5-main branch]
2024-06-03 19:23:20 -04:00

46 lines
860 B
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "UbaBinaryReaderWriter.h"
#include "UbaEvent.h"
namespace uba
{
class Event;
struct GroupAffinity;
class Thread
{
public:
Thread();
Thread(Function<u32()>&& func);
~Thread();
void Start(Function<u32()>&& func);
bool Wait(u32 milliseconds = ~0u, Event* wakeupEvent = nullptr);
bool GetGroupAffinity(GroupAffinity& out);
private:
Function<u32()> m_func;
void* m_handle = nullptr;
ReaderWriterLock m_funcLock;
#if !PLATFORM_WINDOWS
Event m_finished;
#endif
Thread(const Thread&) = delete;
void operator=(const Thread&) = delete;
};
struct GroupAffinity
{
u64 mask = 0;
u16 group = 0;
};
bool SetThreadGroupAffinity(void* nativeThreadHandle, const GroupAffinity& affinity);
bool AlternateThreadGroupAffinity(void* nativeThreadHandle);
}