From f446fd1fe51edbbd76d9e4ec84b5e11682f47d88 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Thu, 11 Oct 2018 14:49:52 -0400 Subject: [PATCH] Kernel: add KernelSystem class --- src/core/core.cpp | 12 ++++++++++-- src/core/core.h | 12 ++++++++++++ src/core/hle/kernel/kernel.cpp | 4 ++-- src/core/hle/kernel/kernel.h | 10 +++++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 4f7a5e908..d5445b438 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -196,7 +196,7 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { archive_manager = std::make_unique(); HW::Init(); - Kernel::Init(system_mode); + kernel = std::make_unique(system_mode); Service::Init(*this, service_manager); GDBStub::Init(); @@ -230,6 +230,14 @@ const Service::FS::ArchiveManager& System::ArchiveManager() const { return *archive_manager; } +Kernel::KernelSystem& System::Kernel() { + return *kernel; +} + +const Kernel::KernelSystem& System::Kernel() const { + return *kernel; +} + void System::RegisterSoftwareKeyboard(std::shared_ptr swkbd) { registered_swkbd = std::move(swkbd); } @@ -248,7 +256,7 @@ void System::Shutdown() { GDBStub::Shutdown(); VideoCore::Shutdown(); Service::Shutdown(); - Kernel::Shutdown(); + kernel.reset(); HW::Shutdown(); telemetry_session.reset(); #ifdef ENABLE_SCRIPTING diff --git a/src/core/core.h b/src/core/core.h index cecd29896..9341f79a4 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -36,6 +36,10 @@ class ArchiveManager; } } // namespace Service +namespace Kernel { +class KernelSystem; +} + namespace Core { class System { @@ -167,6 +171,12 @@ public: /// Gets a const reference to the archive manager const Service::FS::ArchiveManager& ArchiveManager() const; + /// Gets a reference to the kernel + Kernel::KernelSystem& Kernel(); + + /// Gets a const reference to the kernel + const Kernel::KernelSystem& Kernel() const; + PerfStats perf_stats; FrameLimiter frame_limiter; @@ -241,6 +251,8 @@ private: std::unique_ptr archive_manager; + std::unique_ptr kernel; + static System s_instance; ResultStatus status = ResultStatus::Success; diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index d494914e3..7991f77cf 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -17,7 +17,7 @@ namespace Kernel { std::atomic Object::next_object_id{0}; /// Initialize the kernel -void Init(u32 system_mode) { +KernelSystem::KernelSystem(u32 system_mode) { ConfigMem::Init(); Kernel::MemoryInit(system_mode); @@ -33,7 +33,7 @@ void Init(u32 system_mode) { } /// Shutdown the kernel -void Shutdown() { +KernelSystem::~KernelSystem() { g_handle_table.Clear(); // Free all kernel objects Kernel::ThreadingShutdown(); diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 2bc45d7db..c19cdc92d 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -8,10 +8,10 @@ namespace Kernel { -/// Initialize the kernel with the specified system mode. -void Init(u32 system_mode); - -/// Shutdown the kernel -void Shutdown(); +class KernelSystem { +public: + explicit KernelSystem(u32 system_mode); + ~KernelSystem(); +}; } // namespace Kernel