summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
authorGravatar Subv2016-12-03 22:38:14 -0500
committerGravatar Subv2016-12-03 22:38:14 -0500
commit8634b8cb83755b6c6554faa11c0e488d2ad21f90 (patch)
tree93c2e91659ccd2925210dcffb559213edbd2a64a /src/core/hle/kernel/thread.h
parentMerge pull request #2251 from JayFoxRox/remove-version (diff)
downloadyuzu-8634b8cb83755b6c6554faa11c0e488d2ad21f90.tar.gz
yuzu-8634b8cb83755b6c6554faa11c0e488d2ad21f90.tar.xz
yuzu-8634b8cb83755b6c6554faa11c0e488d2ad21f90.zip
Threading: Reworked the way our scheduler works.
Threads will now be awakened when the objects they're waiting on are signaled, instead of repeating the WaitSynchronization call every now and then. The scheduler is now called once after every SVC call, and once after a thread is awakened from sleep by its timeout callback. This new implementation is based off reverse-engineering of the real kernel. See https://gist.github.com/Subv/02f29bd9f1e5deb7aceea1e8f019c8f4 for a more detailed description of how the real kernel handles rescheduling.
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index e0ffcea8a..63b97b74f 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <string> 7#include <string>
8#include <unordered_map>
8#include <vector> 9#include <vector>
9#include <boost/container/flat_set.hpp> 10#include <boost/container/flat_set.hpp>
10#include "common/common_types.h" 11#include "common/common_types.h"
@@ -125,6 +126,16 @@ public:
125 void SetWaitSynchronizationOutput(s32 output); 126 void SetWaitSynchronizationOutput(s32 output);
126 127
127 /** 128 /**
129 * Retrieves the index that this particular object occupies in the list of objects
130 * that the thread passed to WaitSynchronizationN.
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.
133 */
134 s32 GetWaitObjectIndex(WaitObject* object) {
135 return wait_objects_index[object->GetObjectId()];
136 }
137
138 /**
128 * Stops a thread, invalidating it from further use 139 * Stops a thread, invalidating it from further use
129 */ 140 */
130 void Stop(); 141 void Stop();
@@ -154,16 +165,16 @@ public:
154 165
155 VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread 166 VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread
156 167
157 bool waitsynch_waited; ///< Set to true if the last svcWaitSynch call caused the thread to wait
158
159 /// Mutexes currently held by this thread, which will be released when it exits. 168 /// Mutexes currently held by this thread, which will be released when it exits.
160 boost::container::flat_set<SharedPtr<Mutex>> held_mutexes; 169 boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
161 170
162 SharedPtr<Process> owner_process; ///< Process that owns this thread 171 SharedPtr<Process> owner_process; ///< Process that owns this thread
163 std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on 172 std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on
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.
174
164 VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address 175 VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address
165 bool wait_all; ///< True if the thread is waiting on all objects before resuming 176
166 bool wait_set_output; ///< True if the output parameter should be set on thread wakeup 177 bool wait_set_output; ///< True if the WaitSynchronizationN output parameter should be set on thread wakeup
167 178
168 std::string name; 179 std::string name;
169 180
@@ -215,10 +226,9 @@ void WaitCurrentThread_Sleep();
215 * @param wait_objects Kernel objects that we are waiting on 226 * @param wait_objects Kernel objects that we are waiting on
216 * @param wait_set_output If true, set the output parameter on thread wakeup (for 227 * @param wait_set_output If true, set the output parameter on thread wakeup (for
217 * WaitSynchronizationN only) 228 * WaitSynchronizationN only)
218 * @param wait_all If true, wait on all objects before resuming (for WaitSynchronizationN only)
219 */ 229 */
220void WaitCurrentThread_WaitSynchronization(std::vector<SharedPtr<WaitObject>> wait_objects, 230void WaitCurrentThread_WaitSynchronization(std::vector<SharedPtr<WaitObject>> wait_objects,
221 bool wait_set_output, bool wait_all); 231 bool wait_set_output);
222 232
223/** 233/**
224 * Waits the current thread from an ArbitrateAddress call 234 * Waits the current thread from an ArbitrateAddress call