summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/k_condition_variable.cpp4
-rw-r--r--src/core/hle/kernel/k_light_lock.cpp2
-rw-r--r--src/core/hle/kernel/k_process.cpp2
-rw-r--r--src/core/hle/kernel/k_thread.cpp12
-rw-r--r--src/core/hle/kernel/k_thread.h14
5 files changed, 23 insertions, 11 deletions
diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cpp
index 8dae78397..f40cf92b1 100644
--- a/src/core/hle/kernel/k_condition_variable.cpp
+++ b/src/core/hle/kernel/k_condition_variable.cpp
@@ -113,7 +113,7 @@ Result KConditionVariable::SignalToAddress(VAddr addr) {
113 // Remove waiter thread. 113 // Remove waiter thread.
114 bool has_waiters{}; 114 bool has_waiters{};
115 KThread* const next_owner_thread = 115 KThread* const next_owner_thread =
116 owner_thread->RemoveWaiterByKey(std::addressof(has_waiters), addr); 116 owner_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr);
117 117
118 // Determine the next tag. 118 // Determine the next tag.
119 u32 next_value{}; 119 u32 next_value{};
@@ -283,7 +283,7 @@ Result KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout) {
283 // Remove waiter thread. 283 // Remove waiter thread.
284 bool has_waiters{}; 284 bool has_waiters{};
285 KThread* next_owner_thread = 285 KThread* next_owner_thread =
286 cur_thread->RemoveWaiterByKey(std::addressof(has_waiters), addr); 286 cur_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr);
287 287
288 // Update for the next owner thread. 288 // Update for the next owner thread.
289 u32 next_value{}; 289 u32 next_value{};
diff --git a/src/core/hle/kernel/k_light_lock.cpp b/src/core/hle/kernel/k_light_lock.cpp
index b922a67a5..14cb615da 100644
--- a/src/core/hle/kernel/k_light_lock.cpp
+++ b/src/core/hle/kernel/k_light_lock.cpp
@@ -91,7 +91,7 @@ void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) {
91 91
92 // Get the next owner. 92 // Get the next owner.
93 bool has_waiters; 93 bool has_waiters;
94 KThread* next_owner = owner_thread->RemoveWaiterByKey( 94 KThread* next_owner = owner_thread->RemoveKernelWaiterByKey(
95 std::addressof(has_waiters), reinterpret_cast<uintptr_t>(std::addressof(tag))); 95 std::addressof(has_waiters), reinterpret_cast<uintptr_t>(std::addressof(tag)));
96 96
97 // Pass the lock to the next owner. 97 // Pass the lock to the next owner.
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index 514f20ef4..d44f6e921 100644
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -157,7 +157,7 @@ bool KProcess::ReleaseUserException(KThread* thread) {
157 157
158 // Remove waiter thread. 158 // Remove waiter thread.
159 bool has_waiters{}; 159 bool has_waiters{};
160 if (KThread* next = thread->RemoveWaiterByKey( 160 if (KThread* next = thread->RemoveKernelWaiterByKey(
161 std::addressof(has_waiters), 161 std::addressof(has_waiters),
162 reinterpret_cast<uintptr_t>(std::addressof(exception_thread))); 162 reinterpret_cast<uintptr_t>(std::addressof(exception_thread)));
163 next != nullptr) { 163 next != nullptr) {
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 2831df733..8c403f5fd 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -933,12 +933,14 @@ void KThread::AddHeldLock(LockWithPriorityInheritanceInfo* lock_info) {
933 held_lock_info_list.push_front(*lock_info); 933 held_lock_info_list.push_front(*lock_info);
934} 934}
935 935
936KThread::LockWithPriorityInheritanceInfo* KThread::FindHeldLock(VAddr address_key_) { 936KThread::LockWithPriorityInheritanceInfo* KThread::FindHeldLock(VAddr address_key_,
937 bool is_kernel_address_key_) {
937 ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); 938 ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
938 939
939 // Try to find an existing held lock. 940 // Try to find an existing held lock.
940 for (auto& held_lock : held_lock_info_list) { 941 for (auto& held_lock : held_lock_info_list) {
941 if (held_lock.GetAddressKey() == address_key_) { 942 if (held_lock.GetAddressKey() == address_key_ &&
943 held_lock.GetIsKernelAddressKey() == is_kernel_address_key_) {
942 return std::addressof(held_lock); 944 return std::addressof(held_lock);
943 } 945 }
944 } 946 }
@@ -961,7 +963,7 @@ void KThread::AddWaiterImpl(KThread* thread) {
961 } 963 }
962 964
963 // Get the relevant lock info. 965 // Get the relevant lock info.
964 auto* lock_info = this->FindHeldLock(address_key_); 966 auto* lock_info = this->FindHeldLock(address_key_, is_kernel_address_key_);
965 if (lock_info == nullptr) { 967 if (lock_info == nullptr) {
966 // Create a new lock for the address key. 968 // Create a new lock for the address key.
967 lock_info = 969 lock_info =
@@ -1067,11 +1069,11 @@ void KThread::RemoveWaiter(KThread* thread) {
1067 } 1069 }
1068} 1070}
1069 1071
1070KThread* KThread::RemoveWaiterByKey(bool* out_has_waiters, VAddr key) { 1072KThread* KThread::RemoveWaiterByKey(bool* out_has_waiters, VAddr key, bool is_kernel_address_key_) {
1071 ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); 1073 ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
1072 1074
1073 // Get the relevant lock info. 1075 // Get the relevant lock info.
1074 auto* lock_info = this->FindHeldLock(key); 1076 auto* lock_info = this->FindHeldLock(key, is_kernel_address_key_);
1075 if (lock_info == nullptr) { 1077 if (lock_info == nullptr) {
1076 *out_has_waiters = false; 1078 *out_has_waiters = false;
1077 return nullptr; 1079 return nullptr;
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index e09dcbea0..bd125f5f1 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -595,7 +595,13 @@ public:
595 595
596 [[nodiscard]] Result GetThreadContext3(std::vector<u8>& out); 596 [[nodiscard]] Result GetThreadContext3(std::vector<u8>& out);
597 597
598 [[nodiscard]] KThread* RemoveWaiterByKey(bool* out_has_waiters, VAddr key); 598 [[nodiscard]] KThread* RemoveUserWaiterByKey(bool* out_has_waiters, VAddr key) {
599 return this->RemoveWaiterByKey(out_has_waiters, key, false);
600 }
601
602 [[nodiscard]] KThread* RemoveKernelWaiterByKey(bool* out_has_waiters, VAddr key) {
603 return this->RemoveWaiterByKey(out_has_waiters, key, true);
604 }
599 605
600 [[nodiscard]] VAddr GetAddressKey() const { 606 [[nodiscard]] VAddr GetAddressKey() const {
601 return address_key; 607 return address_key;
@@ -666,6 +672,9 @@ public:
666 } 672 }
667 673
668private: 674private:
675 [[nodiscard]] KThread* RemoveWaiterByKey(bool* out_has_waiters, VAddr key,
676 bool is_kernel_address_key);
677
669 static constexpr size_t PriorityInheritanceCountMax = 10; 678 static constexpr size_t PriorityInheritanceCountMax = 10;
670 union SyncObjectBuffer { 679 union SyncObjectBuffer {
671 std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> sync_objects{}; 680 std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> sync_objects{};
@@ -850,7 +859,7 @@ public:
850 } 859 }
851 860
852 void AddHeldLock(LockWithPriorityInheritanceInfo* lock_info); 861 void AddHeldLock(LockWithPriorityInheritanceInfo* lock_info);
853 LockWithPriorityInheritanceInfo* FindHeldLock(VAddr address_key); 862 LockWithPriorityInheritanceInfo* FindHeldLock(VAddr address_key, bool is_kernel_address_key);
854 863
855private: 864private:
856 using LockWithPriorityInheritanceInfoList = 865 using LockWithPriorityInheritanceInfoList =
@@ -926,6 +935,7 @@ public:
926 condvar_key = cv_key; 935 condvar_key = cv_key;
927 address_key = address; 936 address_key = address;
928 address_key_value = value; 937 address_key_value = value;
938 is_kernel_address_key = false;
929 } 939 }
930 940
931 void ClearConditionVariable() { 941 void ClearConditionVariable() {