ksys/res: Start adding ResourceUnit and Cache

This commit is contained in:
Léo Lam
2020-09-25 17:49:07 +02:00
parent 26baae29de
commit b1926813b7
16 changed files with 573 additions and 43 deletions
+25
View File
@@ -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