summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2016-12-04 15:58:36 +0100
committerSubv <subv2112@gmail.com>2016-12-04 15:58:36 +0100
commitbdad00c73f46106ba78995bdde1b50349e940b09 (patch)
tree1c39ab11c8e995f2cbba8a5f602ab64819085b22 /src/core/hle/kernel
parentThreading: Reworked the way our scheduler works. (diff)
downloadyuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar
yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.gz
yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.bz2
yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.lz
yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.xz
yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.zst
yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.zip
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/kernel.cpp13
-rw-r--r--src/core/hle/kernel/thread.h19
2 files changed, 22 insertions, 10 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index be7a5a6d8..6d358def7 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -33,7 +33,7 @@ void WaitObject::RemoveWaitingThread(Thread* thread) {
SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
// Remove the threads that are ready or already running from our waitlist
- waiting_threads.erase(std::remove_if(waiting_threads.begin(), waiting_threads.end(), [](SharedPtr<Thread> thread) -> bool {
+ waiting_threads.erase(std::remove_if(waiting_threads.begin(), waiting_threads.end(), [](const SharedPtr<Thread>& thread) -> bool {
return thread->status == THREADSTATUS_RUNNING || thread->status == THREADSTATUS_READY;
}), waiting_threads.end());
@@ -42,12 +42,11 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
auto candidate_threads = waiting_threads;
- // Eliminate all threads that are waiting on more than one object, and not all of them are ready
- candidate_threads.erase(std::remove_if(candidate_threads.begin(), candidate_threads.end(), [](SharedPtr<Thread> thread) -> bool {
- for (auto object : thread->wait_objects)
- if (object->ShouldWait())
- return true;
- return false;
+ // Eliminate all threads that are waiting on more than one object, and not all of said objects are ready
+ candidate_threads.erase(std::remove_if(candidate_threads.begin(), candidate_threads.end(), [](const SharedPtr<Thread>& thread) -> bool {
+ return std::any_of(thread->wait_objects.begin(), thread->wait_objects.end(), [](const SharedPtr<WaitObject>& object) -> bool {
+ return object->ShouldWait();
+ });
}), candidate_threads.end());
// Return the thread with the lowest priority value (The one with the highest priority)
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 63b97b74f..1b29fb3a3 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -131,8 +131,8 @@ public:
* It is used to set the output value of WaitSynchronizationN when the thread is awakened.
* @param object Object to query the index of.
*/
- s32 GetWaitObjectIndex(WaitObject* object) {
- return wait_objects_index[object->GetObjectId()];
+ s32 GetWaitObjectIndex(const WaitObject* object) const {
+ return wait_objects_index.at(object->GetObjectId());
}
/**
@@ -148,6 +148,15 @@ public:
return tls_address;
}
+ /**
+ * Returns whether this thread is waiting for all the objects in
+ * its wait list to become ready, as a result of a WaitSynchronizationN call
+ * with wait_all = true, or a ReplyAndReceive call.
+ */
+ bool IsWaitingAll() const {
+ return !wait_objects.empty();
+ }
+
Core::ThreadContext context;
u32 thread_id;
@@ -169,7 +178,11 @@ public:
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
SharedPtr<Process> owner_process; ///< Process that owns this thread
- std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on
+
+ /// Objects that the thread is waiting on.
+ /// This is only populated when the thread should wait for all the objects to become ready.
+ std::vector<SharedPtr<WaitObject>> wait_objects;
+
std::unordered_map<int, s32> wait_objects_index; ///< Mapping of Object ids to their position in the last waitlist that this object waited on.
VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address