diff options
| author | Léo Lam <leo@leolam.fr> | 2020-09-25 17:49:07 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2020-09-26 21:03:24 +0200 |
| commit | b1926813b720b1f8088db62160cb60430b0b11f2 (patch) | |
| tree | 952e11cf32bbaddde90b1285a4a3b55a7931f07f /src/KingSystem/Resource/resCache.cpp | |
| parent | 26baae29de4bcd2d3c847285e37b52d47d2b73e6 (diff) | |
ksys/res: Start adding ResourceUnit and Cache
Diffstat (limited to 'src/KingSystem/Resource/resCache.cpp')
| -rw-r--r-- | src/KingSystem/Resource/resCache.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/KingSystem/Resource/resCache.cpp b/src/KingSystem/Resource/resCache.cpp new file mode 100644 index 00000000..4f7abb62 --- /dev/null +++ b/src/KingSystem/Resource/resCache.cpp @@ -0,0 +1,25 @@ +#include "KingSystem/Resource/resCache.h" +#include <prim/seadScopedLock.h> +#include "KingSystem/Resource/resCacheCriticalSection.h" + +namespace ksys::res { + +Cache::Cache() = default; + +void Cache::init() {} + +ResourceUnit* Cache::findUnit(const util::StrTreeMapNode::KeyType& key) const { + auto lock = sead::makeScopedLock(gCacheCriticalSection); + ResourceUnitMapNode* node = mMap.find(key); + return node ? node->getUnit() : nullptr; +} + +void Cache::eraseUnit(ResourceUnit* unit) { + auto lock = sead::makeScopedLock(gCacheCriticalSection); + if (unit->isLinkedToCache()) { + mMap.erase(unit->getCacheKey()); + unit->setIsLinkedToCache(false); + } +} + +} // namespace ksys::res |
