summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2019-11-24 20:15:51 -0500
committerGravatar GitHub2019-11-24 20:15:51 -0500
commit9046d4a5485452802b756869b7d27056ba9ea9d7 (patch)
tree2d704d912e9054fb232b73ad69f1bc3966ed97a5 /src/core/hle/kernel/mutex.cpp
parentMerge pull request #3098 from ReinUsesLisp/shader-invalidations (diff)
downloadyuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.gz
yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.xz
yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.zip
kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. (#3154)
* kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. - See https://github.com/citra-emu/citra/pull/4710 for details.
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r--src/core/hle/kernel/mutex.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 663d0f4b6..8493d0f78 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -22,10 +22,10 @@ namespace Kernel {
22 22
23/// Returns the number of threads that are waiting for a mutex, and the highest priority one among 23/// Returns the number of threads that are waiting for a mutex, and the highest priority one among
24/// those. 24/// those.
25static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread( 25static std::pair<std::shared_ptr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
26 const SharedPtr<Thread>& current_thread, VAddr mutex_addr) { 26 const std::shared_ptr<Thread>& current_thread, VAddr mutex_addr) {
27 27
28 SharedPtr<Thread> highest_priority_thread; 28 std::shared_ptr<Thread> highest_priority_thread;
29 u32 num_waiters = 0; 29 u32 num_waiters = 0;
30 30
31 for (const auto& thread : current_thread->GetMutexWaitingThreads()) { 31 for (const auto& thread : current_thread->GetMutexWaitingThreads()) {
@@ -45,14 +45,14 @@ static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
45} 45}
46 46
47/// Update the mutex owner field of all threads waiting on the mutex to point to the new owner. 47/// Update the mutex owner field of all threads waiting on the mutex to point to the new owner.
48static void TransferMutexOwnership(VAddr mutex_addr, SharedPtr<Thread> current_thread, 48static void TransferMutexOwnership(VAddr mutex_addr, std::shared_ptr<Thread> current_thread,
49 SharedPtr<Thread> new_owner) { 49 std::shared_ptr<Thread> new_owner) {
50 const auto threads = current_thread->GetMutexWaitingThreads(); 50 const auto threads = current_thread->GetMutexWaitingThreads();
51 for (const auto& thread : threads) { 51 for (const auto& thread : threads) {
52 if (thread->GetMutexWaitAddress() != mutex_addr) 52 if (thread->GetMutexWaitAddress() != mutex_addr)
53 continue; 53 continue;
54 54
55 ASSERT(thread->GetLockOwner() == current_thread); 55 ASSERT(thread->GetLockOwner() == current_thread.get());
56 current_thread->RemoveMutexWaiter(thread); 56 current_thread->RemoveMutexWaiter(thread);
57 if (new_owner != thread) 57 if (new_owner != thread)
58 new_owner->AddMutexWaiter(thread); 58 new_owner->AddMutexWaiter(thread);
@@ -70,9 +70,10 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle,
70 } 70 }
71 71
72 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 72 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
73 Thread* const current_thread = system.CurrentScheduler().GetCurrentThread(); 73 std::shared_ptr<Thread> current_thread =
74 SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle); 74 SharedFrom(system.CurrentScheduler().GetCurrentThread());
75 SharedPtr<Thread> requesting_thread = handle_table.Get<Thread>(requesting_thread_handle); 75 std::shared_ptr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
76 std::shared_ptr<Thread> requesting_thread = handle_table.Get<Thread>(requesting_thread_handle);
76 77
77 // TODO(Subv): It is currently unknown if it is possible to lock a mutex in behalf of another 78 // TODO(Subv): It is currently unknown if it is possible to lock a mutex in behalf of another
78 // thread. 79 // thread.
@@ -110,7 +111,8 @@ ResultCode Mutex::Release(VAddr address) {
110 return ERR_INVALID_ADDRESS; 111 return ERR_INVALID_ADDRESS;
111 } 112 }
112 113
113 auto* const current_thread = system.CurrentScheduler().GetCurrentThread(); 114 std::shared_ptr<Thread> current_thread =
115 SharedFrom(system.CurrentScheduler().GetCurrentThread());
114 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(current_thread, address); 116 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(current_thread, address);
115 117
116 // There are no more threads waiting for the mutex, release it completely. 118 // There are no more threads waiting for the mutex, release it completely.