Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ThreadManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "CoreGlobals.h"
7#include "Containers/Map.h"
8#include "HAL/CriticalSection.h"
9
10#ifndef PLATFORM_SUPPORTS_ALL_THREAD_BACKTRACES
11 #define PLATFORM_SUPPORTS_ALL_THREAD_BACKTRACES (PLATFORM_WINDOWS || PLATFORM_MAC)
12#endif
13
14class FRunnableThread;
15
16/**
17 * Manages runnables and runnable threads.
18 */
20{
21 /** Critical section for ThreadList */
23
25 /** List of thread objects to be ticked. */
27
28public:
29
30 /**
31 * Used internally to add a new thread object.
32 *
33 * @param Thread thread object.
34 * @see RemoveThread
35 */
36 void AddThread(uint32 ThreadId, FRunnableThread* Thread);
37
38 /**
39 * Used internally to remove thread object.
40 *
41 * @param Thread thread object to be removed.
42 * @see AddThread
43 */
45
46 /** Get the number of registered threads */
47 int32 NumThreads() const { return Threads.Num(); }
48
49 /** Ticks all fake threads and their runnable objects. */
50 void Tick();
51
52 /** Returns the name of a thread given its TLS id */
53 inline static const FString& GetThreadName(uint32 ThreadId)
54 {
55 static FString GameThreadName(TEXT("GameThread"));
56 static FString RenderThreadName(TEXT("RenderThread"));
58 if (ThreadId == GGameThreadId)
59 {
60 return GameThreadName;
61 }
62 else if (ThreadId == GRenderThreadId)
63 {
64 return RenderThreadName;
65 }
67 return Get().GetThreadNameInternal(ThreadId);
68 }
69
71 struct FThreadStackBackTrace
72 {
73 uint32 ThreadId;
74 FString ThreadName;
75 TArray<uint64, TInlineAllocator<100>> ProgramCounters;
76 };
77
78 void GetAllThreadStackBackTraces(TArray<FThreadStackBackTrace>& StackTraces);
79#endif
80
81 /**
82 * Enumerate each thread.
83 *
84 */
85 void ForEachThread(TFunction<void(uint32 ThreadId, FRunnableThread* Thread)> Func);
86
87 /**
88 * Access to the singleton object.
89 *
90 * @return Thread manager object.
91 */
93
94private:
95
96 friend class FForkProcessHelper;
97
98 /** Returns a list of registered forkable threads */
100
101 /** Returns internal name of a the thread given its TLS id */
102 const FString& GetThreadNameInternal(uint32 ThreadId);
103};
uint32 GRenderThreadId
uint32 GGameThreadId
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
#define PLATFORM_MAC
Definition Platform.h:16
#define PLATFORM_WINDOWS
Definition Platform.h:4
#define TEXT(x)
Definition Platform.h:1108
#define PLATFORM_SUPPORTS_ALL_THREAD_BACKTRACES
FWindowsCriticalSection FCriticalSection
ARK_API FString(const ANSICHAR *Str)
Definition String.cpp:249
TArray< FRunnableThread * > GetForkableThreads()
const FString & GetThreadNameInternal(uint32 ThreadId)
static const FString & GetThreadName(uint32 ThreadId)
static FThreadManager & Get()
void AddThread(uint32 ThreadId, FRunnableThread *Thread)
FCriticalSection ThreadsCritical
void ForEachThread(TFunction< void(uint32 ThreadId, FRunnableThread *Thread)> Func)
void RemoveThread(FRunnableThread *Thread)
int32 NumThreads() const