Thread.h
4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
#include "il2cpp-config.h"
#include "utils/NonCopyable.h"
struct MethodInfo;
struct Il2CppArray;
struct Il2CppDomain;
struct Il2CppObject;
struct Il2CppThread;
struct Il2CppInternalThread;
struct Il2CppString;
namespace il2cpp
{
namespace vm
{
// System.Threading.ThreadState
enum ThreadState
{
kThreadStateRunning = 0x00000000,
kThreadStateStopRequested = 0x00000001,
kThreadStateSuspendRequested = 0x00000002,
kThreadStateBackground = 0x00000004,
kThreadStateUnstarted = 0x00000008,
kThreadStateStopped = 0x00000010,
kThreadStateWaitSleepJoin = 0x00000020,
kThreadStateSuspended = 0x00000040,
kThreadStateAbortRequested = 0x00000080,
kThreadStateAborted = 0x00000100
};
// System.Threading.ApartmentState
enum ThreadApartmentState
{
kThreadApartmentStateSTA = 0x00000000,
kThreadApartmentStateMTA = 0x00000001,
kThreadApartmentStateUnknown = 0x00000002
};
class LIBIL2CPP_CODEGEN_API Thread
{
public:
static std::string GetName(Il2CppInternalThread* thread);
static void SetName(Il2CppThread* thread, Il2CppString* name);
static void SetName(Il2CppInternalThread* thread, Il2CppString* name);
static Il2CppThread* Current();
static Il2CppThread* Attach(Il2CppDomain *domain);
static void Detach(Il2CppThread *thread);
static void WalkFrameStack(Il2CppThread *thread, Il2CppFrameWalkFunc func, void *user_data);
static Il2CppThread** GetAllAttachedThreads(size_t &size);
static void KillAllBackgroundThreadsAndWaitForForegroundThreads();
static Il2CppThread* Main();
static bool IsVmThread(Il2CppThread *thread);
static uint64_t GetId(Il2CppThread *thread);
static uint64_t GetId(Il2CppInternalThread* thread);
static void RequestInterrupt(Il2CppThread* thread);
static void CheckCurrentThreadForInterruptAndThrowIfNecessary();
static bool RequestAbort(Il2CppThread* thread);
static void CheckCurrentThreadForAbortAndThrowIfNecessary();
static void ResetAbort(Il2CppThread* thread);
static bool RequestAbort(Il2CppInternalThread* thread);
static void ResetAbort(Il2CppInternalThread* thread);
static void SetPriority(Il2CppThread* thread, int32_t priority);
static int32_t GetPriority(Il2CppThread* thread);
struct NativeThreadAbortException {};
public:
// internal
static void Initialize();
static void UnInitialize();
static void AdjustStaticData();
static int32_t AllocThreadStaticData(int32_t size);
static void FreeThreadStaticData(Il2CppThread *thread);
static void* GetThreadStaticData(int32_t offset);
static void* GetThreadStaticDataForThread(int32_t offset, Il2CppThread* thread);
static void* GetThreadStaticDataForThread(int32_t offset, Il2CppInternalThread* thread);
static void Register(Il2CppThread *thread);
static void Unregister(Il2CppThread *thread);
static void Setup(Il2CppThread* thread);
/// Initialize and register thread.
/// NOTE: Must be called on thread!
static void Initialize(Il2CppThread *thread, Il2CppDomain* domain);
static void Uninitialize(Il2CppThread *thread);
static void SetMain(Il2CppThread* thread);
static void SetState(Il2CppThread *thread, ThreadState value);
static ThreadState GetState(Il2CppThread *thread);
static void ClrState(Il2CppThread* thread, ThreadState clr);
static void FullMemoryBarrier();
static int32_t GetNewManagedId();
static Il2CppInternalThread* CurrentInternal();
static void ClrState(Il2CppInternalThread* thread, ThreadState clr);
static void SetState(Il2CppInternalThread *thread, ThreadState value);
static ThreadState GetState(Il2CppInternalThread *thread);
static bool TestState(Il2CppInternalThread* thread, ThreadState value);
static Il2CppInternalThread* CreateInternal(void(*func)(void*), void* arg, bool threadpool_thread, uint32_t stack_size);
static void Stop(Il2CppInternalThread* thread);
static void Sleep(uint32_t ms);
static bool YieldInternal();
private:
static Il2CppThread* s_MainThread;
};
class ThreadStateSetter : il2cpp::utils::NonCopyable
{
public:
ThreadStateSetter(ThreadState state) : m_State(state)
{
m_Thread = il2cpp::vm::Thread::Current();
Thread::SetState(m_Thread, m_State);
}
~ThreadStateSetter()
{
Thread::ClrState(m_Thread, m_State);
}
private:
ThreadState m_State;
Il2CppThread* m_Thread;
};
} /* namespace vm */
} /* namespace il2cpp */