diff --git a/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp b/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp index 89cad629e..e248bca2a 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp @@ -22,10 +22,10 @@ namespace ams::fssystem { NON_COPYABLE(KeySlotCacheAccessor); NON_MOVEABLE(KeySlotCacheAccessor); private: - std::unique_lock lk; + std::scoped_lock lk; const s32 slot_index; public: - KeySlotCacheAccessor(s32 idx, std::unique_lock &&l) : lk(std::move(l)), slot_index(idx) { /* ... */ } + KeySlotCacheAccessor(s32 idx, std::scoped_lock &&l) : lk(std::move(l)), slot_index(idx) { /* ... */ } s32 GetKeySlotIndex() const { return this->slot_index; } }; @@ -79,7 +79,7 @@ namespace ams::fssystem { } Result Find(std::unique_ptr *out, const void *key, size_t key_size, s32 key2) { - std::unique_lock lk(this->mutex); + std::scoped_lock lk(this->mutex); KeySlotCacheEntryList *lists[2] = { std::addressof(this->high_priority_mru_list), std::addressof(this->low_priority_mru_list) }; for (auto list : lists) { @@ -100,12 +100,12 @@ namespace ams::fssystem { } void AddEntry(KeySlotCacheEntry *entry) { - std::unique_lock lk(this->mutex); + std::scoped_lock lk(this->mutex); this->low_priority_mru_list.push_front(*entry); } private: Result AllocateFromLru(std::unique_ptr *out, KeySlotCacheEntryList &dst_list, const void *key, size_t key_size, s32 key2) { - std::unique_lock lk(this->mutex); + std::scoped_lock lk(this->mutex); KeySlotCacheEntryList &src_list = this->low_priority_mru_list.empty() ? this->high_priority_mru_list : this->low_priority_mru_list; AMS_ASSERT(!src_list.empty()); diff --git a/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp b/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp index f063812de..2c7c8a1a2 100644 --- a/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp +++ b/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp @@ -55,14 +55,14 @@ namespace ams::os::impl { manager.NotifyThreadNameChanged(thread); { - std::unique_lock lk(GetReference(thread->cs_thread)); + GetReference(thread->cs_thread).Lock(); while (thread->state == ThreadType::State_Initialized) { GetReference(thread->cv_thread).Wait(GetPointer(thread->cs_thread)); } + const auto new_state = thread->state; + GetReference(thread->cs_thread).Unlock(); - if (thread->state == ThreadType::State_Started) { - lk.unlock(); - + if (new_state == ThreadType::State_Started) { thread->function(thread->argument); } }