summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-28 12:30:33 -0400
committerGravatar Lioncash2018-08-28 22:31:51 -0400
commit0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5 (patch)
tree2d7bb143d490c3984bff6deda426b818bf27d552 /src/core/hle/kernel/thread.h
parentMerge pull request #1193 from lioncash/priv (diff)
downloadyuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.tar.gz
yuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.tar.xz
yuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.zip
kernel: Eliminate kernel global state
As means to pave the way for getting rid of global state within core, This eliminates kernel global state by removing all globals. Instead this introduces a KernelCore class which acts as a kernel instance. This instance lives in the System class, which keeps its lifetime contained to the lifetime of the System class. This also forces the kernel types to actually interact with the main kernel instance itself instead of having transient kernel state placed all over several translation units, keeping everything together. It also has a nice consequence of making dependencies much more explicit. This also makes our initialization a tad bit more correct. Previously we were creating a kernel process before the actual kernel was initialized, which doesn't really make much sense. The KernelCore class itself follows the PImpl idiom, which allows keeping all the implementation details sealed away from everything else, which forces the use of the exposed API and allows us to avoid any unnecessary inclusions within the main kernel header.
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 06edc296d..20f50458b 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -56,6 +56,7 @@ enum class ThreadWakeupReason {
56 56
57namespace Kernel { 57namespace Kernel {
58 58
59class KernelCore;
59class Process; 60class Process;
60class Scheduler; 61class Scheduler;
61 62
@@ -63,6 +64,7 @@ class Thread final : public WaitObject {
63public: 64public:
64 /** 65 /**
65 * Creates and returns a new thread. The new thread is immediately scheduled 66 * Creates and returns a new thread. The new thread is immediately scheduled
67 * @param kernel The kernel instance this thread will be created under.
66 * @param name The friendly name desired for the thread 68 * @param name The friendly name desired for the thread
67 * @param entry_point The address at which the thread should start execution 69 * @param entry_point The address at which the thread should start execution
68 * @param priority The thread's priority 70 * @param priority The thread's priority
@@ -72,8 +74,9 @@ public:
72 * @param owner_process The parent process for the thread 74 * @param owner_process The parent process for the thread
73 * @return A shared pointer to the newly created thread 75 * @return A shared pointer to the newly created thread
74 */ 76 */
75 static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority, 77 static ResultVal<SharedPtr<Thread>> Create(KernelCore& kernel, std::string name,
76 u64 arg, s32 processor_id, VAddr stack_top, 78 VAddr entry_point, u32 priority, u64 arg,
79 s32 processor_id, VAddr stack_top,
77 SharedPtr<Process> owner_process); 80 SharedPtr<Process> owner_process);
78 81
79 std::string GetName() const override { 82 std::string GetName() const override {
@@ -263,7 +266,7 @@ public:
263 u64 affinity_mask{0x1}; 266 u64 affinity_mask{0x1};
264 267
265private: 268private:
266 Thread(); 269 explicit Thread(KernelCore& kernel);
267 ~Thread() override; 270 ~Thread() override;
268 271
269 std::shared_ptr<std::vector<u8>> tls_memory = std::make_shared<std::vector<u8>>(); 272 std::shared_ptr<std::vector<u8>> tls_memory = std::make_shared<std::vector<u8>>();
@@ -271,12 +274,13 @@ private:
271 274
272/** 275/**
273 * Sets up the primary application thread 276 * Sets up the primary application thread
277 * @param kernel The kernel instance to create the main thread under.
274 * @param entry_point The address at which the thread should start execution 278 * @param entry_point The address at which the thread should start execution
275 * @param priority The priority to give the main thread 279 * @param priority The priority to give the main thread
276 * @param owner_process The parent process for the main thread 280 * @param owner_process The parent process for the main thread
277 * @return A shared pointer to the main thread 281 * @return A shared pointer to the main thread
278 */ 282 */
279SharedPtr<Thread> SetupMainThread(VAddr entry_point, u32 priority, 283SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 priority,
280 SharedPtr<Process> owner_process); 284 SharedPtr<Process> owner_process);
281 285
282/** 286/**
@@ -294,14 +298,4 @@ void WaitCurrentThread_Sleep();
294 */ 298 */
295void ExitCurrentThread(); 299void ExitCurrentThread();
296 300
297/**
298 * Initialize threading
299 */
300void ThreadingInit();
301
302/**
303 * Shutdown threading
304 */
305void ThreadingShutdown();
306
307} // namespace Kernel 301} // namespace Kernel