1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-10 06:01:52 +00:00

kern: use 13.0.0 revised KLightLock logic

This commit is contained in:
Michael Scire 2021-10-19 02:45:29 -07:00
parent 3fc695aff8
commit 52332e8d75
2 changed files with 12 additions and 15 deletions

View file

@ -37,16 +37,12 @@ namespace ams::kern {
uintptr_t old_tag = m_tag.load(std::memory_order_relaxed); uintptr_t old_tag = m_tag.load(std::memory_order_relaxed);
while (!m_tag.compare_exchange_weak(old_tag, (old_tag == 0) ? cur_thread : old_tag | 1, std::memory_order_acquire)) { while (!m_tag.compare_exchange_weak(old_tag, (old_tag == 0) ? cur_thread : old_tag | 1, std::memory_order_acquire)) {
if ((old_tag | 1) == cur_thread_tag) { /* ... */
return;
}
} }
if ((old_tag == 0) || ((old_tag | 1) == cur_thread_tag)) { if (old_tag == 0 || this->LockSlowPath(old_tag | 1, cur_thread)) {
break; break;
} }
this->LockSlowPath(old_tag | 1, cur_thread);
} }
} }
@ -54,15 +50,14 @@ namespace ams::kern {
MESOSPHERE_ASSERT_THIS(); MESOSPHERE_ASSERT_THIS();
const uintptr_t cur_thread = reinterpret_cast<uintptr_t>(GetCurrentThreadPointer()); const uintptr_t cur_thread = reinterpret_cast<uintptr_t>(GetCurrentThreadPointer());
uintptr_t expected = cur_thread; uintptr_t expected = cur_thread;
do { if (!m_tag.compare_exchange_strong(expected, 0, std::memory_order_release)) {
if (expected != cur_thread) { this->UnlockSlowPath(cur_thread);
return this->UnlockSlowPath(cur_thread); }
}
} while (!m_tag.compare_exchange_weak(expected, 0, std::memory_order_release));
} }
void LockSlowPath(uintptr_t owner, uintptr_t cur_thread); bool LockSlowPath(uintptr_t owner, uintptr_t cur_thread);
void UnlockSlowPath(uintptr_t cur_thread); void UnlockSlowPath(uintptr_t cur_thread);
ALWAYS_INLINE bool IsLocked() const { return m_tag.load() != 0; } ALWAYS_INLINE bool IsLocked() const { return m_tag.load() != 0; }

View file

@ -31,7 +31,7 @@ namespace ams::kern {
} }
void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) { bool KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) {
KThread *cur_thread = reinterpret_cast<KThread *>(_cur_thread); KThread *cur_thread = reinterpret_cast<KThread *>(_cur_thread);
ThreadQueueImplForKLightLock wait_queue; ThreadQueueImplForKLightLock wait_queue;
@ -40,8 +40,8 @@ namespace ams::kern {
KScopedSchedulerLock sl; KScopedSchedulerLock sl;
/* Ensure we actually have locking to do. */ /* Ensure we actually have locking to do. */
if (AMS_UNLIKELY(m_tag.load(std::memory_order_relaxed) != _owner)) { if (m_tag.load(std::memory_order_relaxed) != _owner) {
return; return false;
} }
/* Add the current thread as a waiter on the owner. */ /* Add the current thread as a waiter on the owner. */
@ -56,6 +56,8 @@ namespace ams::kern {
owner_thread->ContinueIfHasKernelWaiters(); owner_thread->ContinueIfHasKernelWaiters();
} }
} }
return true;
} }
void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) { void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) {