stratosphere: Use RAII for locks

This renames the Mutex class member functions so that the mutex types
satisfy Lockable.

This makes them usable with standard std::scoped_lock
and std::unique_lock, which lets us use RAII and avoids the need
for a custom RAII wrapper :)
This commit is contained in:
Léo Lam 2018-07-02 16:10:57 +02:00 committed by SciresM
parent 18153713d9
commit 5b3e8e1c5d
11 changed files with 52 additions and 91 deletions

View file

@ -1,3 +1,4 @@
#include <mutex>
#include <switch.h>
#include <stratosphere.hpp>
#include "fsmitm_worker.hpp"
@ -18,10 +19,9 @@ Result FsMitMWorker::AddWaitableCallback(void *arg, Handle *handles, size_t num_
void FsMitMWorker::AddWaitable(IWaitable *waitable) {
g_worker_waiter->add_waitable(waitable);
g_new_waitable_mutex.Lock();
std::scoped_lock lk{g_new_waitable_mutex};
g_new_waitable_event->signal_event();
g_sema_new_waitable_finish.Wait();
g_new_waitable_mutex.Unlock();
}
void FsMitMWorker::Main(void *arg) {

View file

@ -1,3 +1,4 @@
#include <mutex>
#include <switch.h>
#include <stratosphere.hpp>
#include "mitm_query_service.hpp"
@ -8,7 +9,7 @@ static HosMutex g_pid_tid_mutex;
Result MitMQueryUtils::get_associated_tid_for_pid(u64 pid, u64 *tid) {
Result rc = 0xCAFE;
g_pid_tid_mutex.Lock();
std::scoped_lock lk{g_pid_tid_mutex};
for (unsigned int i = 0; i < g_known_pids.size(); i++) {
if (g_known_pids[i] == pid) {
*tid = g_known_tids[i];
@ -16,13 +17,11 @@ Result MitMQueryUtils::get_associated_tid_for_pid(u64 pid, u64 *tid) {
break;
}
}
g_pid_tid_mutex.Unlock();
return rc;
}
void MitMQueryUtils::associate_pid_to_tid(u64 pid, u64 tid) {
g_pid_tid_mutex.Lock();
std::scoped_lock lk{g_pid_tid_mutex};
g_known_pids.push_back(pid);
g_known_tids.push_back(tid);
g_pid_tid_mutex.Unlock();
}
}