From 001675dced1b7b751d1db4f0d6490776c613df2f Mon Sep 17 00:00:00 2001 From: yzct12345 <87620833+yzct12345@users.noreply.github.com> Date: Fri, 13 Aug 2021 18:39:45 +0000 Subject: logging: Simplify and make thread-safe This simplifies the logging system. This also fixes some lost messages on startup. The simplification is simple. I removed unused functions and moved most things in the .h to the .cpp. I replaced the unnecessary linked list with its contents laid out as three member variables. Anything that went through the linked list now directly accesses the backends. Generic functions are replaced with those for each specific use case and there aren't many. This change increases coupling but we gain back more KISS and encapsulation. With those changes it was easy to make it thread-safe. I just removed the mutex and turned a boolean atomic. I was planning to use this thread-safety in my next PR about stacktraces. It was actually async-signal-safety at first but I ended up using a different approach. Anyway getting rid of the linked list is important for that because have the list of backends constantly changing complicates things. --- src/core/core.cpp | 9 +++++++-- src/core/core.h | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index d3e84c4ef..0d3c4182a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -84,8 +84,6 @@ FileSys::StorageId GetStorageIdForFrontendSlot( } // Anonymous namespace -/*static*/ System System::s_instance; - FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, const std::string& path) { // To account for split 00+01+etc files. @@ -425,6 +423,13 @@ struct System::Impl { System::System() : impl{std::make_unique(*this)} {} System::~System() = default; +void System::InitializeGlobalInstance() { + if (s_instance) { + abort(); + } + s_instance = std::unique_ptr(new System); +} + CpuManager& System::GetCpuManager() { return impl->cpu_manager; } diff --git a/src/core/core.h b/src/core/core.h index ea143043c..85836f2f8 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -121,9 +121,14 @@ public: * @returns Reference to the instance of the System singleton class. */ [[deprecated("Use of the global system instance is deprecated")]] static System& GetInstance() { - return s_instance; + if (!s_instance) { + abort(); + } + return *s_instance; } + static void InitializeGlobalInstance(); + /// Enumeration representing the return values of the System Initialize and Load process. enum class ResultStatus : u32 { Success, ///< Succeeded @@ -396,7 +401,7 @@ private: struct Impl; std::unique_ptr impl; - static System s_instance; + inline static std::unique_ptr s_instance{}; }; } // namespace Core -- cgit v1.2.3