1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-10 06:01:52 +00:00

fs: fix keyslotcache unique_lock usage

This commit is contained in:
Michael Scire 2021-01-12 04:37:34 -08:00
parent b4122da6ad
commit b26ebc12e1

View file

@ -22,10 +22,10 @@ namespace ams::fssystem {
NON_COPYABLE(KeySlotCacheAccessor); NON_COPYABLE(KeySlotCacheAccessor);
NON_MOVEABLE(KeySlotCacheAccessor); NON_MOVEABLE(KeySlotCacheAccessor);
private: private:
std::scoped_lock<os::Mutex> lk; std::unique_lock<os::Mutex> lk;
const s32 slot_index; const s32 slot_index;
public: public:
KeySlotCacheAccessor(s32 idx, std::scoped_lock<os::Mutex> &&l) : lk(std::move(l)), slot_index(idx) { /* ... */ } KeySlotCacheAccessor(s32 idx, std::unique_lock<os::Mutex> &&l) : lk(std::move(l)), slot_index(idx) { /* ... */ }
s32 GetKeySlotIndex() const { return this->slot_index; } s32 GetKeySlotIndex() const { return this->slot_index; }
}; };
@ -79,7 +79,7 @@ namespace ams::fssystem {
} }
Result Find(std::unique_ptr<KeySlotCacheAccessor> *out, const void *key, size_t key_size, s32 key2) { Result Find(std::unique_ptr<KeySlotCacheAccessor> *out, const void *key, size_t key_size, s32 key2) {
std::scoped_lock lk(this->mutex); std::unique_lock lk(this->mutex);
KeySlotCacheEntryList *lists[2] = { std::addressof(this->high_priority_mru_list), std::addressof(this->low_priority_mru_list) }; KeySlotCacheEntryList *lists[2] = { std::addressof(this->high_priority_mru_list), std::addressof(this->low_priority_mru_list) };
for (auto list : lists) { for (auto list : lists) {
@ -100,12 +100,12 @@ namespace ams::fssystem {
} }
void AddEntry(KeySlotCacheEntry *entry) { void AddEntry(KeySlotCacheEntry *entry) {
std::scoped_lock lk(this->mutex); std::unique_lock lk(this->mutex);
this->low_priority_mru_list.push_front(*entry); this->low_priority_mru_list.push_front(*entry);
} }
private: private:
Result AllocateFromLru(std::unique_ptr<KeySlotCacheAccessor> *out, KeySlotCacheEntryList &dst_list, const void *key, size_t key_size, s32 key2) { Result AllocateFromLru(std::unique_ptr<KeySlotCacheAccessor> *out, KeySlotCacheEntryList &dst_list, const void *key, size_t key_size, s32 key2) {
std::scoped_lock lk(this->mutex); std::unique_lock lk(this->mutex);
KeySlotCacheEntryList &src_list = this->low_priority_mru_list.empty() ? this->high_priority_mru_list : this->low_priority_mru_list; KeySlotCacheEntryList &src_list = this->low_priority_mru_list.empty() ? this->high_priority_mru_list : this->low_priority_mru_list;
AMS_ASSERT(!src_list.empty()); AMS_ASSERT(!src_list.empty());