summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/mutex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r--src/core/hle/kernel/mutex.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 663d0f4b6..061e9bcb0 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -22,10 +22,10 @@ namespace Kernel {
/// Returns the number of threads that are waiting for a mutex, and the highest priority one among
/// those.
-static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
- const SharedPtr<Thread>& current_thread, VAddr mutex_addr) {
+static std::pair<std::shared_ptr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
+ const std::shared_ptr<Thread>& current_thread, VAddr mutex_addr) {
- SharedPtr<Thread> highest_priority_thread;
+ std::shared_ptr<Thread> highest_priority_thread;
u32 num_waiters = 0;
for (const auto& thread : current_thread->GetMutexWaitingThreads()) {
@@ -45,14 +45,14 @@ static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
}
/// Update the mutex owner field of all threads waiting on the mutex to point to the new owner.
-static void TransferMutexOwnership(VAddr mutex_addr, SharedPtr<Thread> current_thread,
- SharedPtr<Thread> new_owner) {
+static void TransferMutexOwnership(VAddr mutex_addr, std::shared_ptr<Thread> current_thread,
+ std::shared_ptr<Thread> new_owner) {
const auto threads = current_thread->GetMutexWaitingThreads();
for (const auto& thread : threads) {
if (thread->GetMutexWaitAddress() != mutex_addr)
continue;
- ASSERT(thread->GetLockOwner() == current_thread);
+ ASSERT(thread->GetLockOwner() == current_thread.get());
current_thread->RemoveMutexWaiter(thread);
if (new_owner != thread)
new_owner->AddMutexWaiter(thread);
@@ -70,15 +70,16 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle,
}
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
- Thread* const current_thread = system.CurrentScheduler().GetCurrentThread();
- SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
- SharedPtr<Thread> requesting_thread = handle_table.Get<Thread>(requesting_thread_handle);
+ std::shared_ptr<Thread> current_thread =
+ SharedFrom(system.CurrentScheduler().GetCurrentThread());
+ std::shared_ptr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
+ std::shared_ptr<Thread> requesting_thread = handle_table.Get<Thread>(requesting_thread_handle);
// TODO(Subv): It is currently unknown if it is possible to lock a mutex in behalf of another
// thread.
ASSERT(requesting_thread == current_thread);
- const u32 addr_value = Memory::Read32(address);
+ const u32 addr_value = system.Memory().Read32(address);
// If the mutex isn't being held, just return success.
if (addr_value != (holding_thread_handle | Mutex::MutexHasWaitersFlag)) {
@@ -110,12 +111,13 @@ ResultCode Mutex::Release(VAddr address) {
return ERR_INVALID_ADDRESS;
}
- auto* const current_thread = system.CurrentScheduler().GetCurrentThread();
+ std::shared_ptr<Thread> current_thread =
+ SharedFrom(system.CurrentScheduler().GetCurrentThread());
auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(current_thread, address);
// There are no more threads waiting for the mutex, release it completely.
if (thread == nullptr) {
- Memory::Write32(address, 0);
+ system.Memory().Write32(address, 0);
return RESULT_SUCCESS;
}
@@ -130,7 +132,7 @@ ResultCode Mutex::Release(VAddr address) {
}
// Grant the mutex to the next waiting thread and resume it.
- Memory::Write32(address, mutex_value);
+ system.Memory().Write32(address, mutex_value);
ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex);
thread->ResumeFromWait();