From 3a4841e40302d50b21064be7bc248b249ac88467 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 18:10:06 -0400 Subject: core: Don't construct instance of Core::System, just to access its live instance This would result in a lot of allocations and related object construction, just to toss it all away immediately after the call. These are definitely not intentional, and it was intended that all of these should have been accessing the static function GetInstance() through the name itself, not constructed instances. --- src/core/core.cpp | 2 +- src/core/hle/kernel/thread.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index 8335d502e..7936c5b56 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -29,7 +29,7 @@ System::~System() = default; /// Runs a CPU core while the system is powered on static void RunCpuCore(std::shared_ptr cpu_state) { - while (Core::System().GetInstance().IsPoweredOn()) { + while (Core::System::GetInstance().IsPoweredOn()) { cpu_state->RunLoop(true); } } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 9a9746585..0b3c66428 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -165,7 +165,7 @@ void Thread::CancelWakeupTimer() { static boost::optional GetNextProcessorId(u64 mask) { for (s32 index = 0; index < Core::NUM_CPU_CORES; ++index) { if (mask & (1ULL << index)) { - if (!Core::System().GetInstance().Scheduler(index)->GetCurrentThread()) { + if (!Core::System::GetInstance().Scheduler(index)->GetCurrentThread()) { // Core is enabled and not running any threads, use this one return index; } @@ -215,14 +215,14 @@ void Thread::ResumeFromWait() { new_processor_id = processor_id; } if (ideal_core != -1 && - Core::System().GetInstance().Scheduler(ideal_core)->GetCurrentThread() == nullptr) { + Core::System::GetInstance().Scheduler(ideal_core)->GetCurrentThread() == nullptr) { new_processor_id = ideal_core; } ASSERT(*new_processor_id < 4); // Add thread to new core's scheduler - auto& next_scheduler = Core::System().GetInstance().Scheduler(*new_processor_id); + auto& next_scheduler = Core::System::GetInstance().Scheduler(*new_processor_id); if (*new_processor_id != processor_id) { // Remove thread from previous core's scheduler @@ -325,7 +325,7 @@ ResultVal> Thread::Create(std::string name, VAddr entry_point, thread->name = std::move(name); thread->callback_handle = wakeup_callback_handle_table.Create(thread).Unwrap(); thread->owner_process = owner_process; - thread->scheduler = Core::System().GetInstance().Scheduler(processor_id); + thread->scheduler = Core::System::GetInstance().Scheduler(processor_id); thread->scheduler->AddThread(thread, priority); // Find the next available TLS index, and mark it as used @@ -481,14 +481,14 @@ void Thread::ChangeCore(u32 core, u64 mask) { new_processor_id = processor_id; } if (ideal_core != -1 && - Core::System().GetInstance().Scheduler(ideal_core)->GetCurrentThread() == nullptr) { + Core::System::GetInstance().Scheduler(ideal_core)->GetCurrentThread() == nullptr) { new_processor_id = ideal_core; } ASSERT(*new_processor_id < 4); // Add thread to new core's scheduler - auto& next_scheduler = Core::System().GetInstance().Scheduler(*new_processor_id); + auto& next_scheduler = Core::System::GetInstance().Scheduler(*new_processor_id); if (*new_processor_id != processor_id) { // Remove thread from previous core's scheduler -- cgit v1.2.3 From 10d2ab80989e1362fe9cc206e0708d7aeeda5d3a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 18:15:16 -0400 Subject: core: Make System's default constructor private This makes it a compilation error to construct additional instances of the System class directly, preventing accidental wasteful constructions over and over. --- src/core/core.cpp | 2 ++ src/core/core.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index 7936c5b56..ae3849a36 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -25,6 +25,8 @@ namespace Core { /*static*/ System System::s_instance; +System::System() = default; + System::~System() = default; /// Runs a CPU core while the system is powered on diff --git a/src/core/core.h b/src/core/core.h index f90f085ad..c6f69f001 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -168,6 +168,8 @@ public: } private: + System(); + /// Returns the currently running CPU core Cpu& CurrentCpuCore(); -- cgit v1.2.3