stratosphere: use SdkMutex/SdkRecursiveMutex over Mutex

This commit is contained in:
Michael Scire
2021-09-29 22:52:50 -07:00
parent a4fe1bb5d8
commit 41ab4c2c68
70 changed files with 188 additions and 645 deletions

View File

@@ -92,9 +92,9 @@ namespace ams::fs {
FileHandle handle;
bool close_file;
s64 size;
os::Mutex mutex;
os::SdkMutex mutex;
public:
constexpr explicit FileHandleStorage(FileHandle handle, bool close_file) : handle(handle), close_file(close_file), size(InvalidSize), mutex(false) { /* ... */ }
constexpr explicit FileHandleStorage(FileHandle handle, bool close_file) : handle(handle), close_file(close_file), size(InvalidSize), mutex() { /* ... */ }
constexpr explicit FileHandleStorage(FileHandle handle) : FileHandleStorage(handle, false) { /* ... */ }
virtual ~FileHandleStorage() override {

View File

@@ -42,11 +42,11 @@ namespace ams::fssrv {
class PeakCheckableMemoryResourceFromExpHeap : public ams::MemoryResource {
private:
lmem::HeapHandle heap_handle;
os::Mutex mutex;
os::SdkMutex mutex;
size_t peak_free_size;
size_t current_free_size;
public:
constexpr explicit PeakCheckableMemoryResourceFromExpHeap(size_t heap_size) : heap_handle(nullptr), mutex(false), peak_free_size(heap_size), current_free_size(heap_size) { /* ... */ }
constexpr explicit PeakCheckableMemoryResourceFromExpHeap(size_t heap_size) : heap_handle(nullptr), mutex(), peak_free_size(heap_size), current_free_size(heap_size) { /* ... */ }
void SetHeapHandle(lmem::HeapHandle handle) {
this->heap_handle = handle;
@@ -57,7 +57,7 @@ namespace ams::fssrv {
void ClearPeak() { this->peak_free_size = this->current_free_size; }
std::scoped_lock<os::Mutex> GetScopedLock() {
std::scoped_lock<os::SdkMutex> GetScopedLock() {
return std::scoped_lock(this->mutex);
}

View File

@@ -192,7 +192,7 @@ namespace ams::fssystem {
size_t peak_free_size;
size_t peak_total_allocatable_size;
size_t retried_count;
mutable os::Mutex mutex;
mutable os::SdkRecursiveMutex mutex;
public:
static constexpr size_t QueryWorkBufferSize(s32 max_cache_count, s32 max_order) {
const auto buddy_size = FileSystemBuddyHeap::QueryWorkBufferSize(max_order);
@@ -200,7 +200,7 @@ namespace ams::fssystem {
return buddy_size + table_size;
}
public:
FileSystemBufferManager() : total_size(), peak_free_size(), peak_total_allocatable_size(), retried_count(), mutex(true) { /* ... */ }
FileSystemBufferManager() : total_size(), peak_free_size(), peak_total_allocatable_size(), retried_count(), mutex() { /* ... */ }
virtual ~FileSystemBufferManager() { /* ... */ }

View File

@@ -33,7 +33,7 @@ namespace ams::fssystem {
char key[2][KeySize];
char iv[IvSize];
const size_t block_size;
os::Mutex mutex;
os::SdkMutex mutex;
public:
AesXtsStorage(IStorage *base, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, size_t block_size);

View File

@@ -34,7 +34,7 @@ namespace ams::fssystem {
virtual ~DirectoryRedirectionFileSystem();
protected:
inline util::optional<std::scoped_lock<os::Mutex>> GetAccessorLock() const {
inline util::optional<std::scoped_lock<os::SdkMutex>> GetAccessorLock() const {
/* No accessor lock is needed. */
return util::nullopt;
}

View File

@@ -24,7 +24,7 @@ namespace ams::fssystem {
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>;
friend class impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>;
private:
os::Mutex accessor_mutex;
os::SdkMutex accessor_mutex;
s32 open_writable_files;
public:
DirectorySaveDataFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs);
@@ -33,9 +33,9 @@ namespace ams::fssystem {
virtual ~DirectorySaveDataFileSystem();
protected:
inline util::optional<std::scoped_lock<os::Mutex>> GetAccessorLock() {
inline util::optional<std::scoped_lock<os::SdkMutex>> GetAccessorLock() {
/* We have a real accessor lock that we want to use. */
return util::make_optional<std::scoped_lock<os::Mutex>>(this->accessor_mutex);
return util::make_optional<std::scoped_lock<os::SdkMutex>>(this->accessor_mutex);
}
private:
Result AllocateWorkBuffer(std::unique_ptr<u8[]> *out, size_t *out_size, size_t ideal_size);

View File

@@ -30,11 +30,11 @@ namespace ams::fssystem {
private:
save::HierarchicalIntegrityVerificationStorage integrity_storage;
save::FileSystemBufferManagerSet buffers;
os::Mutex mutex;
os::SdkRecursiveMutex mutex;
Hash master_hash;
std::unique_ptr<fs::MemoryStorage> master_hash_storage;
public:
IntegrityRomFsStorage() : mutex(true) { /* ... */ }
IntegrityRomFsStorage() : mutex() { /* ... */ }
virtual ~IntegrityRomFsStorage() override { this->Finalize(); }
Result Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, IBufferManager *bm);

View File

@@ -32,7 +32,7 @@ namespace ams::fssystem {
virtual ~SubDirectoryFileSystem();
protected:
inline util::optional<std::scoped_lock<os::Mutex>> GetAccessorLock() const {
inline util::optional<std::scoped_lock<os::SdkMutex>> GetAccessorLock() const {
/* No accessor lock is needed. */
return util::nullopt;
}

View File

@@ -62,7 +62,7 @@ namespace ams::fssystem::save {
};
private:
IBufferManager *buffer_manager;
os::Mutex *mutex;
os::SdkRecursiveMutex *mutex;
std::unique_ptr<CacheEntry[], ::ams::fs::impl::Deleter> entries;
IStorage *data_storage;
Result last_result;
@@ -78,7 +78,7 @@ namespace ams::fssystem::save {
BlockCacheBufferedStorage();
virtual ~BlockCacheBufferedStorage() override;
Result Initialize(IBufferManager *bm, os::Mutex *mtx, IStorage *data, s64 data_size, size_t verif_block_size, s32 max_cache_entries, bool is_real_data, s8 buffer_level, bool is_keep_burst_mode, fs::StorageType storage_type);
Result Initialize(IBufferManager *bm, os::SdkRecursiveMutex *mtx, IStorage *data, s64 data_size, size_t verif_block_size, s32 max_cache_entries, bool is_real_data, s8 buffer_level, bool is_keep_burst_mode, fs::StorageType storage_type);
void Finalize();
virtual Result Read(s64 offset, void *buffer, size_t size) override;

View File

@@ -38,7 +38,7 @@ namespace ams::fssystem::save {
s32 cache_count;
Cache *next_acquire_cache;
Cache *next_fetch_cache;
os::Mutex mutex;
os::SdkMutex mutex;
bool bulk_read_enabled;
public:
BufferedStorage();

View File

@@ -147,7 +147,7 @@ namespace ams::fssystem::save {
}
private:
FileSystemBufferManagerSet *buffers;
os::Mutex *mutex;
os::SdkRecursiveMutex *mutex;
IntegrityVerificationStorage verify_storages[MaxLayers - 1];
BlockCacheBufferedStorage buffer_storages[MaxLayers - 1];
s64 data_size;
@@ -157,7 +157,7 @@ namespace ams::fssystem::save {
HierarchicalIntegrityVerificationStorage() : buffers(nullptr), mutex(nullptr), data_size(-1), is_written_for_rollback(false) { /* ... */ }
virtual ~HierarchicalIntegrityVerificationStorage() override { this->Finalize(); }
Result Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::Mutex *mtx, fs::StorageType storage_type);
Result Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::SdkRecursiveMutex *mtx, fs::StorageType storage_type);
void Finalize();
virtual Result Read(s64 offset, void *buffer, size_t size) override;

View File

@@ -63,14 +63,14 @@ namespace ams::kvdb {
bool Contains(const void *key, size_t key_size);
};
private:
os::Mutex lock;
os::SdkMutex lock;
Path dir_path;
Cache cache;
private:
Path GetPath(const void *key, size_t key_size);
Result GetKey(size_t *out_size, void *out_key, size_t max_out_size, const FileName &file_name);
public:
FileKeyValueStore() : lock(false) { /* ... */ }
FileKeyValueStore() : lock() { /* ... */ }
/* Basic accessors. */
Result Initialize(const char *dir);

View File

@@ -85,7 +85,7 @@ namespace ams::lmem::impl {
void *heap_start;
void *heap_end;
os::MutexType mutex;
os::SdkMutexType mutex;
u8 option;
ImplementationHeapHead impl_head;
};

View File

@@ -28,7 +28,7 @@ namespace ams::lr {
sf::SharedPointer<IRegisteredLocationResolver> registered_location_resolver = nullptr;
sf::SharedPointer<IAddOnContentLocationResolver> add_on_content_location_resolver = nullptr;
os::Mutex mutex{false};
os::SdkMutex mutex{};
public:
/* Actual commands. */
Result OpenLocationResolver(sf::Out<sf::SharedPointer<ILocationResolver>> out, ncm::StorageId storage_id);

View File

@@ -102,7 +102,7 @@ namespace ams::ncm {
ContentMetaDatabaseRoot() { /* ... */ }
};
private:
os::Mutex mutex;
os::SdkRecursiveMutex mutex;
bool initialized;
ContentStorageRoot content_storage_roots[MaxContentStorageRoots];
ContentMetaDatabaseRoot content_meta_database_roots[MaxContentMetaDatabaseRoots];
@@ -111,8 +111,8 @@ namespace ams::ncm {
RightsIdCache rights_id_cache;
RegisteredHostContent registered_host_content;
public:
ContentManagerImpl() : mutex(true), initialized(false), num_content_storage_entries(0), num_content_meta_entries(0), rights_id_cache(), registered_host_content() {
/* ... */
ContentManagerImpl() : mutex(), initialized(false), num_content_storage_entries(0), num_content_meta_entries(0), rights_id_cache(), registered_host_content() {
/* ... */
};
~ContentManagerImpl();
public:

View File

@@ -86,13 +86,13 @@ namespace ams::ncm {
StorageId install_storage;
InstallTaskDataBase *data;
InstallProgress progress;
os::Mutex progress_mutex;
os::SdkMutex progress_mutex;
u32 config;
os::Mutex cancel_mutex;
os::SdkMutex cancel_mutex;
bool cancel_requested;
InstallThroughput throughput;
TimeSpan throughput_start_time;
os::Mutex throughput_mutex;
os::SdkMutex throughput_mutex;
FirmwareVariationId firmware_variation_id;
private:
ALWAYS_INLINE Result SetLastResultOnFailure(Result result) {
@@ -102,7 +102,7 @@ namespace ams::ncm {
return result;
}
public:
InstallTaskBase() : data(), progress(), progress_mutex(false), cancel_mutex(false), cancel_requested(), throughput_mutex(false) { /* ... */ }
InstallTaskBase() : data(), progress(), progress_mutex(), cancel_mutex(), cancel_requested(), throughput_mutex() { /* ... */ }
virtual ~InstallTaskBase() { /* ... */ };
public:
virtual void Cancel();

View File

@@ -40,13 +40,13 @@ namespace ams::ncm {
class HeapState {
private:
os::Mutex mutex;
os::SdkMutex mutex;
lmem::HeapHandle heap_handle;
size_t total_alloc_size;
size_t peak_total_alloc_size;
size_t peak_alloc_size;
public:
constexpr HeapState() : mutex(false), heap_handle(nullptr), total_alloc_size(0), peak_total_alloc_size(0), peak_alloc_size(0) { /* ... */ }
constexpr HeapState() : mutex(), heap_handle(nullptr), total_alloc_size(0), peak_total_alloc_size(0), peak_alloc_size(0) { /* ... */ }
void Initialize(lmem::HeapHandle heap_handle);
void Allocate(size_t size);

View File

@@ -84,7 +84,7 @@ namespace ams::sf::cmif {
private:
using EntryList = typename util::IntrusiveListMemberTraits<&Entry::free_list_node>::ListType;
private:
os::Mutex lock;
os::SdkMutex lock;
EntryList free_list;
Entry *entries;
size_t num_entries;
@@ -114,13 +114,13 @@ namespace ams::sf::cmif {
}
};
private:
os::Mutex entry_owner_lock;
os::SdkMutex entry_owner_lock;
EntryManager entry_manager;
private:
virtual void *AllocateDomain() = 0;
virtual void FreeDomain(void *) = 0;
protected:
ServerDomainManager(DomainEntryStorage *entry_storage, size_t entry_count) : entry_owner_lock(false), entry_manager(entry_storage, entry_count) { /* ... */ }
ServerDomainManager(DomainEntryStorage *entry_storage, size_t entry_count) : entry_owner_lock(), entry_manager(entry_storage, entry_count) { /* ... */ }
inline DomainServiceObject *AllocateDomainServiceObject() {
void *storage = this->AllocateDomain();

View File

@@ -80,9 +80,9 @@ namespace ams::sf::hipc {
os::Event notify_event;
os::WaitableHolderType notify_event_holder;
os::Mutex waitable_selection_mutex;
os::SdkMutex waitable_selection_mutex;
os::Mutex waitlist_mutex;
os::SdkMutex waitlist_mutex;
os::WaitableManagerType waitlist;
private:
virtual void RegisterSessionToWaitList(ServerSession *session) override final;
@@ -192,7 +192,7 @@ namespace ams::sf::hipc {
ServerManagerBase(DomainEntryStorage *entry_storage, size_t entry_count) :
ServerDomainSessionManager(entry_storage, entry_count),
request_stop_event(os::EventClearMode_ManualClear), notify_event(os::EventClearMode_ManualClear),
waitable_selection_mutex(false), waitlist_mutex(false)
waitable_selection_mutex(), waitlist_mutex()
{
/* Link waitables. */
os::InitializeWaitableManager(std::addressof(this->waitable_manager));
@@ -259,7 +259,7 @@ namespace ams::sf::hipc {
using ServerManagerBase::DomainStorage;
private:
/* Resource storage. */
os::Mutex resource_mutex;
os::SdkMutex resource_mutex;
util::TypedStorage<Server> server_storages[MaxServers];
bool server_allocated[MaxServers];
util::TypedStorage<ServerSession> session_storages[MaxSessions];
@@ -370,7 +370,7 @@ namespace ams::sf::hipc {
return this->GetObjectBySessionIndex(session, this->saved_messages_start, hipc::TlsMessageBufferSize);
}
public:
ServerManager() : ServerManagerBase(this->domain_entry_storages, ManagerOptions::MaxDomainObjects), resource_mutex(false) {
ServerManager() : ServerManagerBase(this->domain_entry_storages, ManagerOptions::MaxDomainObjects), resource_mutex() {
/* Clear storages. */
#define SF_SM_MEMCLEAR(obj) if constexpr (sizeof(obj) > 0) { std::memset(obj, 0, sizeof(obj)); }
SF_SM_MEMCLEAR(this->server_storages);

View File

@@ -355,7 +355,7 @@ namespace ams::tipc {
using PortAllocatorTuple = std::tuple<typename PortInfos::Allocator...>;
private:
os::Mutex m_mutex;
os::SdkRecursiveMutex m_mutex;
os::TlsSlot m_tls_slot;
PortManagerTuple m_port_managers;
PortAllocatorTuple m_port_allocators;
@@ -390,11 +390,11 @@ namespace ams::tipc {
os::StartThread(m_port_threads + Ix);
}
public:
ServerManagerImpl() : m_mutex(true), m_tls_slot(), m_port_managers(), m_port_allocators() { /* ... */ }
ServerManagerImpl() : m_mutex(), m_tls_slot(), m_port_managers(), m_port_allocators() { /* ... */ }
os::TlsSlot GetTlsSlot() const { return m_tls_slot; }
os::Mutex &GetMutex() { return m_mutex; }
os::SdkRecursiveMutex &GetMutex() { return m_mutex; }
void Initialize() {
/* Initialize our tls slot. */