From ba98bf058adeb10c7935be55b1b439d7f86443df Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sat, 24 Jun 2023 18:30:13 +0300 Subject: [PATCH] logging: Address some issues --- src/android/app/src/main/jni/id_cache.cpp | 6 ------ src/android/app/src/main/jni/native.cpp | 6 ++---- src/citra/citra.cpp | 1 - src/citra_qt/main.cpp | 1 - src/common/bounded_threadsafe_queue.h | 3 ++- src/common/file_util.cpp | 2 +- src/common/logging/backend.cpp | 6 ++++++ src/common/logging/formatter.h | 2 +- src/core/core.cpp | 16 ++-------------- src/core/core.h | 8 ++++---- src/dedicated_room/CMakeLists.txt | 2 +- 11 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/android/app/src/main/jni/id_cache.cpp b/src/android/app/src/main/jni/id_cache.cpp index c2aa048a8..e737d19ee 100644 --- a/src/android/app/src/main/jni/id_cache.cpp +++ b/src/android/app/src/main/jni/id_cache.cpp @@ -180,12 +180,6 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) { if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION) != JNI_OK) return JNI_ERR; - // Initialize Logger - Log::Filter log_filter; - log_filter.ParseFilterString(Settings::values.log_filter.GetValue()); - Log::SetGlobalFilter(log_filter); - Log::AddBackend(std::make_unique()); - // Initialize misc classes s_savestate_info_class = reinterpret_cast( env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$SavestateInfo"))); diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index e9ea0cb37..d1071ad3b 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -438,10 +438,8 @@ void Java_org_citra_citra_1emu_NativeLibrary_CreateConfigFile(JNIEnv* env, void Java_org_citra_citra_1emu_NativeLibrary_CreateLogFile(JNIEnv* env, [[maybe_unused]] jclass clazz) { - Log::RemoveBackend(Log::FileBackend::Name()); - FileUtil::CreateFullPath(FileUtil::GetUserPath(FileUtil::UserPath::LogDir)); - Log::AddBackend(std::make_unique( - FileUtil::GetUserPath(FileUtil::UserPath::LogDir) + LOG_FILE)); + Common::Log::Initialize(); + Common::Log::Start(); LOG_INFO(Frontend, "Logging backend initialised"); } diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index e3b71d26d..3a9640c6e 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -330,7 +330,6 @@ int main(int argc, char** argv) { return -1; } - Core::System::InitializeGlobalInstance(); auto& system = Core::System::GetInstance(); auto& movie = Core::Movie::GetInstance(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index cc76ecd8e..7a16bbfd3 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -2880,7 +2880,6 @@ int main(int argc, char* argv[]) { // generating shaders setlocale(LC_ALL, "C"); - Core::System::InitializeGlobalInstance(); auto& system{Core::System::GetInstance()}; GMainWindow main_window(system); diff --git a/src/common/bounded_threadsafe_queue.h b/src/common/bounded_threadsafe_queue.h index 04d190572..15c9c1db0 100644 --- a/src/common/bounded_threadsafe_queue.h +++ b/src/common/bounded_threadsafe_queue.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,7 @@ private: const size_t pos = write_index % Capacity; // Emplace into the queue. - std::construct_at(std::addressof(m_data[pos]), std::forward(args)...); + new (std::addressof(m_data[pos])) T(std::forward(args)...); // Increment the write index. ++m_write_index; diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 11ff6bcf5..3fa335d35 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include "common/assert.h" #include "common/common_funcs.h" #include "common/common_paths.h" diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 36f4a3f24..d868b2609 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -352,6 +352,9 @@ private: lambda(static_cast(debugger_backend)); lambda(static_cast(color_console_backend)); lambda(static_cast(file_backend)); +#ifdef ANDROID + lambda(static_cast(lc_backend)); +#endif } static void Deleter(Impl* ptr) { @@ -394,6 +397,9 @@ private: DebuggerBackend debugger_backend{}; ColorConsoleBackend color_console_backend{}; FileBackend file_backend; +#ifdef ANDROID + LogcatBackend lc_backend{}; +#endif MPSCQueue message_queue{}; std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; diff --git a/src/common/logging/formatter.h b/src/common/logging/formatter.h index e27850db1..ad6adb143 100644 --- a/src/common/logging/formatter.h +++ b/src/common/logging/formatter.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include // adapted from https://github.com/fmtlib/fmt/issues/2704 // a generic formatter for enum classes diff --git a/src/core/core.cpp b/src/core/core.cpp index 4d4d567e9..f3bbc12d7 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -52,6 +52,8 @@ namespace Core { +/*static*/ System System::s_instance; + template <> Core::System& Global() { return System::GetInstance(); @@ -69,20 +71,6 @@ Core::Timing& Global() { System::~System() = default; -System& System::GetInstance() { - if (!s_instance) { - throw std::runtime_error("Using System instance before its initialization"); - } - return *s_instance; -} - -void System::InitializeGlobalInstance() { - if (s_instance) { - throw std::runtime_error("Reinitializing Global System instance."); - } - s_instance = std::unique_ptr(new System); -} - System::ResultStatus System::RunLoop(bool tight_loop) { status = ResultStatus::Success; if (!IsPoweredOn()) { diff --git a/src/core/core.h b/src/core/core.h index 9bc49c9c3..b29fc20e2 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -73,9 +73,9 @@ public: * Gets the instance of the System singleton class. * @returns Reference to the instance of the System singleton class. */ - [[nodiscard]] static System& GetInstance(); - - static void InitializeGlobalInstance(); + [[nodiscard]] static System& GetInstance() { + return s_instance; + } /// Enumeration representing the return values of the System Initialize and Load process. enum class ResultStatus : u32 { @@ -392,7 +392,7 @@ private: std::unique_ptr exclusive_monitor; private: - inline static std::unique_ptr s_instance; + static System s_instance; std::atomic_bool is_powered_on{}; diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt index 7f130a9a8..4df160a8d 100644 --- a/src/dedicated_room/CMakeLists.txt +++ b/src/dedicated_room/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(citra-room create_target_directory_groups(citra-room) -target_link_libraries(citra-room PRIVATE citra_common network) +target_link_libraries(citra-room PRIVATE citra_common citra_core network) if (ENABLE_WEB_SERVICE) target_compile_definitions(citra-room PRIVATE -DENABLE_WEB_SERVICE) target_link_libraries(citra-room PRIVATE web_service)