From 0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 Aug 2018 12:30:33 -0400 Subject: 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. --- src/core/hle/kernel/thread.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/core/hle/kernel/thread.h') 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 { namespace Kernel { +class KernelCore; class Process; class Scheduler; @@ -63,6 +64,7 @@ class Thread final : public WaitObject { public: /** * Creates and returns a new thread. The new thread is immediately scheduled + * @param kernel The kernel instance this thread will be created under. * @param name The friendly name desired for the thread * @param entry_point The address at which the thread should start execution * @param priority The thread's priority @@ -72,8 +74,9 @@ public: * @param owner_process The parent process for the thread * @return A shared pointer to the newly created thread */ - static ResultVal> Create(std::string name, VAddr entry_point, u32 priority, - u64 arg, s32 processor_id, VAddr stack_top, + static ResultVal> Create(KernelCore& kernel, std::string name, + VAddr entry_point, u32 priority, u64 arg, + s32 processor_id, VAddr stack_top, SharedPtr owner_process); std::string GetName() const override { @@ -263,7 +266,7 @@ public: u64 affinity_mask{0x1}; private: - Thread(); + explicit Thread(KernelCore& kernel); ~Thread() override; std::shared_ptr> tls_memory = std::make_shared>(); @@ -271,12 +274,13 @@ private: /** * Sets up the primary application thread + * @param kernel The kernel instance to create the main thread under. * @param entry_point The address at which the thread should start execution * @param priority The priority to give the main thread * @param owner_process The parent process for the main thread * @return A shared pointer to the main thread */ -SharedPtr SetupMainThread(VAddr entry_point, u32 priority, +SharedPtr SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 priority, SharedPtr owner_process); /** @@ -294,14 +298,4 @@ void WaitCurrentThread_Sleep(); */ void ExitCurrentThread(); -/** - * Initialize threading - */ -void ThreadingInit(); - -/** - * Shutdown threading - */ -void ThreadingShutdown(); - } // namespace Kernel -- cgit v1.2.3