From 5694c9b34b8e0240fb63cc8c086965b070a995f9 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Sat, 26 Nov 2022 01:48:08 +0530 Subject: [PATCH] Rename `KThread::waitKey` to `KThread::waitMutex` It was determined that `waitKey` is too ambiguous when waiter members are used for both mutexes and condition variables. --- .../main/cpp/skyline/kernel/types/KProcess.cpp | 18 +++++++++--------- .../main/cpp/skyline/kernel/types/KThread.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp index 7a88cf39..2c103fc3 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp @@ -139,7 +139,7 @@ namespace skyline::kernel::type { state.scheduler->RemoveThread(); thread->waitThread = owner; - thread->waitKey = mutex; + thread->waitMutex = mutex; thread->waitTag = tag; } @@ -158,18 +158,18 @@ namespace skyline::kernel::type { std::scoped_lock lock{state.thread->waiterMutex}; auto &waiters{state.thread->waiters}; - auto nextOwnerIt{std::find_if(waiters.begin(), waiters.end(), [mutex](const std::shared_ptr &thread) { return thread->waitKey == mutex; })}; + auto nextOwnerIt{std::find_if(waiters.begin(), waiters.end(), [mutex](const std::shared_ptr &thread) { return thread->waitMutex == mutex; })}; if (nextOwnerIt != waiters.end()) { auto nextOwner{*nextOwnerIt}; std::scoped_lock nextLock{nextOwner->waiterMutex}; nextOwner->waitThread = std::shared_ptr{nullptr}; - nextOwner->waitKey = nullptr; + nextOwner->waitMutex = nullptr; // Move all threads waiting on this key to the next owner's waiter list std::shared_ptr nextWaiter{}; for (auto it{waiters.erase(nextOwnerIt)}, nextIt{std::next(it)}; it != waiters.end(); it = nextIt++) { auto thread{*it}; - if (thread->waitKey == mutex) { + if (thread->waitMutex == mutex) { nextOwner->waiters.splice(std::upper_bound(nextOwner->waiters.begin(), nextOwner->waiters.end(), (*it)->priority.load(), KThread::IsHigherPriority), waiters, it); thread->waitThread = nextOwner; if (!nextWaiter) @@ -221,7 +221,7 @@ namespace skyline::kernel::type { { // Update all waiter information std::unique_lock lock{state.thread->waiterMutex}; - state.thread->waitKey = mutex; + state.thread->waitMutex = mutex; state.thread->waitTag = tag; state.thread->waitConditionVariable = key; state.thread->waitSignalled = false; @@ -259,7 +259,7 @@ namespace skyline::kernel::type { std::unique_lock lock{state.thread->waiterMutex}; if (state.thread->waitSignalled) { - if (state.thread->waitKey) { + if (state.thread->waitMutex) { auto waitThread{state.thread->waitThread}; std::unique_lock waitLock{waitThread->waiterMutex, std::try_to_lock}; if (!waitLock) { @@ -276,7 +276,7 @@ namespace skyline::kernel::type { waiters.erase(it); state.thread->UpdatePriorityInheritance(); - state.thread->waitKey = nullptr; + state.thread->waitMutex = nullptr; state.thread->waitTag = 0; state.thread->waitThread = nullptr; } else { @@ -284,7 +284,7 @@ namespace skyline::kernel::type { shouldWait = true; } } else { - // If the waitKey is null then we were signalled and are no longer waiting on the associated mutex + // If the waitMutex is null then we were signalled and are no longer waiting on the associated mutex shouldWait = true; } } else { @@ -350,7 +350,7 @@ namespace skyline::kernel::type { std::scoped_lock lock{thread->waiterMutex}; if (thread->waitConditionVariable == conditionVariable) { // If the thread is still waiting on the same condition variable then we can signal it (It could no longer be waiting due to a timeout) - u32 *mutex{thread->waitKey}; + u32 *mutex{thread->waitMutex}; KHandle tag{thread->waitTag}; while (true) { diff --git a/app/src/main/cpp/skyline/kernel/types/KThread.h b/app/src/main/cpp/skyline/kernel/types/KThread.h index 9bf3c083..c6c9908a 100644 --- a/app/src/main/cpp/skyline/kernel/types/KThread.h +++ b/app/src/main/cpp/skyline/kernel/types/KThread.h @@ -63,7 +63,7 @@ namespace skyline { bool forceYield{}; //!< If the thread has been forcefully yielded by another thread std::recursive_mutex waiterMutex; //!< Synchronizes operations on mutation of the waiter members - u32 *waitKey; //!< The key of the mutex which this thread is waiting on + u32 *waitMutex; //!< The key of the mutex which this thread is waiting on KHandle waitTag; //!< The handle of the thread which requested the mutex lock std::shared_ptr waitThread; //!< The thread which this thread is waiting on std::list> waiters; //!< A queue of threads waiting on this thread sorted by priority