From 599b5791920a69dd877ca77a8d718ea3a2c982aa Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 9 Jun 2021 18:00:54 -0700 Subject: [PATCH] Adds a ShutdownStaticTables context function Due to a mixture of allocators this needs to be shutdown in the correct location. A little bit dirty but is necessary without a full refactor --- External/FEXCore/Source/Common/Paths.cpp | 30 ++++++++++++------- External/FEXCore/Source/Common/Paths.h | 1 + .../Source/Interface/Context/Context.cpp | 4 +++ .../FEXCore/include/FEXCore/Core/Context.h | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/External/FEXCore/Source/Common/Paths.cpp b/External/FEXCore/Source/Common/Paths.cpp index da716ce47..54e5f0440 100644 --- a/External/FEXCore/Source/Common/Paths.cpp +++ b/External/FEXCore/Source/Common/Paths.cpp @@ -6,10 +6,13 @@ #include namespace FEXCore::Paths { - std::string CachePath; - std::string EntryCache; + std::unique_ptr CachePath; + std::unique_ptr EntryCache; void InitializePaths() { + CachePath = std::make_unique(); + EntryCache = std::make_unique(); + char const *HomeDir = getenv("HOME"); if (!HomeDir) { @@ -22,29 +25,34 @@ namespace FEXCore::Paths { char *XDGDataDir = getenv("XDG_DATA_DIR"); if (XDGDataDir) { - CachePath = XDGDataDir; + *CachePath = XDGDataDir; } else { if (HomeDir) { - CachePath = HomeDir; + *CachePath = HomeDir; } } - CachePath += "/.fex-emu/"; - EntryCache = CachePath + "/EntryCache/"; + *CachePath += "/.fex-emu/"; + *EntryCache = *CachePath + "/EntryCache/"; // Ensure the folder structure is created for our Data - if (!std::filesystem::exists(EntryCache) && - !std::filesystem::create_directories(EntryCache)) { - LogMan::Msg::D("Couldn't create EntryCache directory: '%s'", EntryCache.c_str()); + if (!std::filesystem::exists(*EntryCache) && + !std::filesystem::create_directories(*EntryCache)) { + LogMan::Msg::D("Couldn't create EntryCache directory: '%s'", EntryCache->c_str()); } } + void ShutdownPaths() { + CachePath.reset(); + EntryCache.reset(); + } + std::string GetCachePath() { - return CachePath; + return *CachePath; } std::string GetEntryCachePath() { - return EntryCache; + return *EntryCache; } } diff --git a/External/FEXCore/Source/Common/Paths.h b/External/FEXCore/Source/Common/Paths.h index 7f92fde1e..f538c04a5 100644 --- a/External/FEXCore/Source/Common/Paths.h +++ b/External/FEXCore/Source/Common/Paths.h @@ -3,6 +3,7 @@ namespace FEXCore::Paths { void InitializePaths(); + void ShutdownPaths(); std::string GetCachePath(); std::string GetEntryCachePath(); } diff --git a/External/FEXCore/Source/Interface/Context/Context.cpp b/External/FEXCore/Source/Interface/Context/Context.cpp index 1c593f7b4..51507880e 100644 --- a/External/FEXCore/Source/Interface/Context/Context.cpp +++ b/External/FEXCore/Source/Interface/Context/Context.cpp @@ -14,6 +14,10 @@ namespace FEXCore::Context { IR::InstallOpcodeHandlers(Mode); } + void ShutdownStaticTables() { + FEXCore::Paths::ShutdownPaths(); + } + FEXCore::Context::Context *CreateNewContext() { return new FEXCore::Context::Context{}; } diff --git a/External/FEXCore/include/FEXCore/Core/Context.h b/External/FEXCore/include/FEXCore/Core/Context.h index 8bf155db3..1e794dfde 100644 --- a/External/FEXCore/include/FEXCore/Core/Context.h +++ b/External/FEXCore/include/FEXCore/Core/Context.h @@ -52,6 +52,7 @@ namespace FEXCore::Context { * @brief This initializes internal FEXCore state that is shared between contexts and requires overhead to setup */ FEX_DEFAULT_VISIBILITY void InitializeStaticTables(OperatingMode Mode = MODE_64BIT); + FEX_DEFAULT_VISIBILITY void ShutdownStaticTables(); /** * @brief [[threadsafe]] Create a new FEXCore context object