diff options
| author | 2016-12-04 09:58:36 -0500 | |
|---|---|---|
| committer | 2016-12-04 09:58:36 -0500 | |
| commit | bdad00c73f46106ba78995bdde1b50349e940b09 (patch) | |
| tree | 1c39ab11c8e995f2cbba8a5f602ab64819085b22 /src/core/hle/kernel | |
| parent | Threading: Reworked the way our scheduler works. (diff) | |
| download | yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.gz yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.tar.xz yuzu-bdad00c73f46106ba78995bdde1b50349e940b09.zip | |
Threading: Added some utility functions and const correctness.
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 19 |
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) { | |||
| 33 | 33 | ||
| 34 | SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { | 34 | SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { |
| 35 | // Remove the threads that are ready or already running from our waitlist | 35 | // Remove the threads that are ready or already running from our waitlist |
| 36 | waiting_threads.erase(std::remove_if(waiting_threads.begin(), waiting_threads.end(), [](SharedPtr<Thread> thread) -> bool { | 36 | waiting_threads.erase(std::remove_if(waiting_threads.begin(), waiting_threads.end(), [](const SharedPtr<Thread>& thread) -> bool { |
| 37 | return thread->status == THREADSTATUS_RUNNING || thread->status == THREADSTATUS_READY; | 37 | return thread->status == THREADSTATUS_RUNNING || thread->status == THREADSTATUS_READY; |
| 38 | }), waiting_threads.end()); | 38 | }), waiting_threads.end()); |
| 39 | 39 | ||
| @@ -42,12 +42,11 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { | |||
| 42 | 42 | ||
| 43 | auto candidate_threads = waiting_threads; | 43 | auto candidate_threads = waiting_threads; |
| 44 | 44 | ||
| 45 | // Eliminate all threads that are waiting on more than one object, and not all of them are ready | 45 | // Eliminate all threads that are waiting on more than one object, and not all of said objects are ready |
| 46 | candidate_threads.erase(std::remove_if(candidate_threads.begin(), candidate_threads.end(), [](SharedPtr<Thread> thread) -> bool { | 46 | candidate_threads.erase(std::remove_if(candidate_threads.begin(), candidate_threads.end(), [](const SharedPtr<Thread>& thread) -> bool { |
| 47 | for (auto object : thread->wait_objects) | 47 | return std::any_of(thread->wait_objects.begin(), thread->wait_objects.end(), [](const SharedPtr<WaitObject>& object) -> bool { |
| 48 | if (object->ShouldWait()) | 48 | return object->ShouldWait(); |
| 49 | return true; | 49 | }); |
| 50 | return false; | ||
| 51 | }), candidate_threads.end()); | 50 | }), candidate_threads.end()); |
| 52 | 51 | ||
| 53 | // Return the thread with the lowest priority value (The one with the highest priority) | 52 | // 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: | |||
| 131 | * It is used to set the output value of WaitSynchronizationN when the thread is awakened. | 131 | * It is used to set the output value of WaitSynchronizationN when the thread is awakened. |
| 132 | * @param object Object to query the index of. | 132 | * @param object Object to query the index of. |
| 133 | */ | 133 | */ |
| 134 | s32 GetWaitObjectIndex(WaitObject* object) { | 134 | s32 GetWaitObjectIndex(const WaitObject* object) const { |
| 135 | return wait_objects_index[object->GetObjectId()]; | 135 | return wait_objects_index.at(object->GetObjectId()); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | /** | 138 | /** |
| @@ -148,6 +148,15 @@ public: | |||
| 148 | return tls_address; | 148 | return tls_address; |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | /** | ||
| 152 | * Returns whether this thread is waiting for all the objects in | ||
| 153 | * its wait list to become ready, as a result of a WaitSynchronizationN call | ||
| 154 | * with wait_all = true, or a ReplyAndReceive call. | ||
| 155 | */ | ||
| 156 | bool IsWaitingAll() const { | ||
| 157 | return !wait_objects.empty(); | ||
| 158 | } | ||
| 159 | |||
| 151 | Core::ThreadContext context; | 160 | Core::ThreadContext context; |
| 152 | 161 | ||
| 153 | u32 thread_id; | 162 | u32 thread_id; |
| @@ -169,7 +178,11 @@ public: | |||
| 169 | boost::container::flat_set<SharedPtr<Mutex>> held_mutexes; | 178 | boost::container::flat_set<SharedPtr<Mutex>> held_mutexes; |
| 170 | 179 | ||
| 171 | SharedPtr<Process> owner_process; ///< Process that owns this thread | 180 | SharedPtr<Process> owner_process; ///< Process that owns this thread |
| 172 | std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on | 181 | |
| 182 | /// Objects that the thread is waiting on. | ||
| 183 | /// This is only populated when the thread should wait for all the objects to become ready. | ||
| 184 | std::vector<SharedPtr<WaitObject>> wait_objects; | ||
| 185 | |||
| 173 | std::unordered_map<int, s32> wait_objects_index; ///< Mapping of Object ids to their position in the last waitlist that this object waited on. | 186 | std::unordered_map<int, s32> wait_objects_index; ///< Mapping of Object ids to their position in the last waitlist that this object waited on. |
| 174 | 187 | ||
| 175 | VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address | 188 | VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address |