From e71398325430d19308b9bf5a724cb6b5bb0f025b Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 18 Dec 2024 00:13:44 -0700 Subject: [PATCH 1/3] Add `UnloadResourcesAsync` to handle threaded unloading. Make `UnloadResources` non-async. Add common `UnloadResourcesProcess` to handle the actual unloading. --- src/resource/ResourceManager.cpp | 30 +++++++++++++++++++++--------- src/resource/ResourceManager.h | 3 +++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index b1f0b6f19..1a65fc839 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -342,24 +342,36 @@ void ResourceManager::DirtyResources(const ResourceFilter& filter) { }); } -void ResourceManager::UnloadResources(const ResourceFilter& filter) { - mThreadPool->submit_task([this, filter]() -> void { - auto list = GetArchiveManager()->ListFiles(filter.IncludeMasks, filter.ExcludeMasks); +void ResourceManager::DirtyResources(const std::string& searchMask) { + DirtyResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }); +} - for (const auto& key : *list.get()) { - UnloadResource({ key, mDefaultCacheOwner, mDefaultCacheArchive }); - } - }); +void ResourceManager::UnloadResourcesAsync(const std::string& searchMask) { + UnloadResourcesAsync({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }); } -void ResourceManager::DirtyResources(const std::string& searchMask) { - DirtyResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }); +void ResourceManager::UnloadResourcesAsync(const ResourceFilter& filter) { + mThreadPool->submit_task([this, filter]() -> void { + UnloadResourcesProcess(filter); + }); } void ResourceManager::UnloadResources(const std::string& searchMask) { UnloadResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }); } +void ResourceManager::UnloadResources(const ResourceFilter& filter) { + UnloadResourcesProcess(filter); +} + +void ResourceManager::UnloadResourcesProcess(const ResourceFilter& filter) { + auto list = GetArchiveManager()->ListFiles(filter.IncludeMasks, filter.ExcludeMasks); + + for (const auto& key : *list.get()) { + UnloadResource({ key, mDefaultCacheOwner, mDefaultCacheArchive }); + } +} + std::shared_ptr ResourceManager::GetArchiveManager() { return mArchiveManager; } diff --git a/src/resource/ResourceManager.h b/src/resource/ResourceManager.h index e3a2e0cce..2994e4ebb 100644 --- a/src/resource/ResourceManager.h +++ b/src/resource/ResourceManager.h @@ -95,6 +95,8 @@ class ResourceManager { void DirtyResources(const ResourceFilter& filter); void UnloadResources(const std::string& searchMask); void UnloadResources(const ResourceFilter& filter); + void UnloadResourcesAsync(const std::string& searchMask); + void UnloadResourcesAsync(const ResourceFilter& filter); bool OtrSignatureCheck(const char* fileName); bool IsAltAssetsEnabled(); @@ -102,6 +104,7 @@ class ResourceManager { protected: std::shared_ptr>> LoadResourcesProcess(const ResourceFilter& filter); + void UnloadResourcesProcess(const ResourceFilter& filter); std::variant> CheckCache(const ResourceIdentifier& identifier, bool loadExact = false); std::shared_ptr LoadFileProcess(const ResourceIdentifier& identifier, From 72bd95b19f5120bef5db544564936b3ad6501969 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 18 Dec 2024 00:35:35 -0700 Subject: [PATCH 2/3] Clang again --- src/resource/ResourceManager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index 1a65fc839..b6f714f2f 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -351,9 +351,7 @@ void ResourceManager::UnloadResourcesAsync(const std::string& searchMask) { } void ResourceManager::UnloadResourcesAsync(const ResourceFilter& filter) { - mThreadPool->submit_task([this, filter]() -> void { - UnloadResourcesProcess(filter); - }); + mThreadPool->submit_task([this, filter]() -> void { UnloadResourcesProcess(filter); }); } void ResourceManager::UnloadResources(const std::string& searchMask) { From fecdb1fa0390c401edf86ea827d2f83f88035e56 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 18 Dec 2024 00:42:09 -0700 Subject: [PATCH 3/3] Add priority argument to `UnloadResourcesAsync` --- src/resource/ResourceManager.cpp | 8 ++++---- src/resource/ResourceManager.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index b6f714f2f..ac0bdf8a7 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -346,12 +346,12 @@ void ResourceManager::DirtyResources(const std::string& searchMask) { DirtyResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }); } -void ResourceManager::UnloadResourcesAsync(const std::string& searchMask) { - UnloadResourcesAsync({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }); +void ResourceManager::UnloadResourcesAsync(const std::string& searchMask, BS::priority_t priority) { + UnloadResourcesAsync({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }, priority); } -void ResourceManager::UnloadResourcesAsync(const ResourceFilter& filter) { - mThreadPool->submit_task([this, filter]() -> void { UnloadResourcesProcess(filter); }); +void ResourceManager::UnloadResourcesAsync(const ResourceFilter& filter, BS::priority_t priority) { + mThreadPool->submit_task([this, filter]() -> void { UnloadResourcesProcess(filter); }, priority); } void ResourceManager::UnloadResources(const std::string& searchMask) { diff --git a/src/resource/ResourceManager.h b/src/resource/ResourceManager.h index 2994e4ebb..db67f137a 100644 --- a/src/resource/ResourceManager.h +++ b/src/resource/ResourceManager.h @@ -95,8 +95,8 @@ class ResourceManager { void DirtyResources(const ResourceFilter& filter); void UnloadResources(const std::string& searchMask); void UnloadResources(const ResourceFilter& filter); - void UnloadResourcesAsync(const std::string& searchMask); - void UnloadResourcesAsync(const ResourceFilter& filter); + void UnloadResourcesAsync(const std::string& searchMask, BS::priority_t priority = BS::pr::normal); + void UnloadResourcesAsync(const ResourceFilter& filter, BS::priority_t priority = BS::pr::normal); bool OtrSignatureCheck(const char* fileName); bool IsAltAssetsEnabled();