summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2014-12-08 20:59:17 -0500
committerGravatar bunnei2014-12-08 20:59:17 -0500
commit3a57856b665f2e4c6ffdeab8b7092f29c86ef3d0 (patch)
treefadd5259fa1f227f73d65b2dbaffd77d20a9c23e /src/core/hle/kernel/thread.cpp
parentMerge pull request #244 from bunnei/cleanup-memmap (diff)
parentThread: Fixed to wait on address when in arbitration. (diff)
downloadyuzu-3a57856b665f2e4c6ffdeab8b7092f29c86ef3d0.tar.gz
yuzu-3a57856b665f2e4c6ffdeab8b7092f29c86ef3d0.tar.xz
yuzu-3a57856b665f2e4c6ffdeab8b7092f29c86ef3d0.zip
Merge pull request #242 from bunnei/fix-address-arbiters
Thread: Fixed to wait on address when in arbitration.
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 8d65dc84d..1e879b45a 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -63,6 +63,7 @@ public:
63 63
64 WaitType wait_type; 64 WaitType wait_type;
65 Handle wait_handle; 65 Handle wait_handle;
66 VAddr wait_address;
66 67
67 std::vector<Handle> waiting_threads; 68 std::vector<Handle> waiting_threads;
68 69
@@ -126,6 +127,7 @@ void ResetThread(Thread* t, u32 arg, s32 lowest_priority) {
126 } 127 }
127 t->wait_type = WAITTYPE_NONE; 128 t->wait_type = WAITTYPE_NONE;
128 t->wait_handle = 0; 129 t->wait_handle = 0;
130 t->wait_address = 0;
129} 131}
130 132
131/// Change a thread to "ready" state 133/// Change a thread to "ready" state
@@ -146,11 +148,17 @@ void ChangeReadyState(Thread* t, bool ready) {
146} 148}
147 149
148/// Verify that a thread has not been released from waiting 150/// Verify that a thread has not been released from waiting
149inline bool VerifyWait(const Thread* thread, WaitType type, Handle wait_handle) { 151static bool VerifyWait(const Thread* thread, WaitType type, Handle wait_handle) {
150 _dbg_assert_(KERNEL, thread != nullptr); 152 _dbg_assert_(KERNEL, thread != nullptr);
151 return (type == thread->wait_type) && (wait_handle == thread->wait_handle) && (thread->IsWaiting()); 153 return (type == thread->wait_type) && (wait_handle == thread->wait_handle) && (thread->IsWaiting());
152} 154}
153 155
156/// Verify that a thread has not been released from waiting (with wait address)
157static bool VerifyWait(const Thread* thread, WaitType type, Handle wait_handle, VAddr wait_address) {
158 _dbg_assert_(KERNEL, thread != nullptr);
159 return VerifyWait(thread, type, wait_handle) && (wait_address == thread->wait_address);
160}
161
154/// Stops the current thread 162/// Stops the current thread
155ResultCode StopThread(Handle handle, const char* reason) { 163ResultCode StopThread(Handle handle, const char* reason) {
156 Thread* thread = g_object_pool.Get<Thread>(handle); 164 Thread* thread = g_object_pool.Get<Thread>(handle);
@@ -169,6 +177,7 @@ ResultCode StopThread(Handle handle, const char* reason) {
169 // Stopped threads are never waiting. 177 // Stopped threads are never waiting.
170 thread->wait_type = WAITTYPE_NONE; 178 thread->wait_type = WAITTYPE_NONE;
171 thread->wait_handle = 0; 179 thread->wait_handle = 0;
180 thread->wait_address = 0;
172 181
173 return RESULT_SUCCESS; 182 return RESULT_SUCCESS;
174} 183}
@@ -197,12 +206,12 @@ Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address) {
197 for (Handle handle : thread_queue) { 206 for (Handle handle : thread_queue) {
198 Thread* thread = g_object_pool.Get<Thread>(handle); 207 Thread* thread = g_object_pool.Get<Thread>(handle);
199 208
200 // TODO(bunnei): Verify arbiter address... 209 if (!VerifyWait(thread, WAITTYPE_ARB, arbiter, address))
201 if (!VerifyWait(thread, WAITTYPE_ARB, arbiter))
202 continue; 210 continue;
203 211
204 if (thread == nullptr) 212 if (thread == nullptr)
205 continue; // TODO(yuriks): Thread handle will hang around forever. Should clean up. 213 continue; // TODO(yuriks): Thread handle will hang around forever. Should clean up.
214
206 if(thread->current_priority <= priority) { 215 if(thread->current_priority <= priority) {
207 highest_priority_thread = handle; 216 highest_priority_thread = handle;
208 priority = thread->current_priority; 217 priority = thread->current_priority;
@@ -222,8 +231,7 @@ void ArbitrateAllThreads(u32 arbiter, u32 address) {
222 for (Handle handle : thread_queue) { 231 for (Handle handle : thread_queue) {
223 Thread* thread = g_object_pool.Get<Thread>(handle); 232 Thread* thread = g_object_pool.Get<Thread>(handle);
224 233
225 // TODO(bunnei): Verify arbiter address... 234 if (VerifyWait(thread, WAITTYPE_ARB, arbiter, address))
226 if (VerifyWait(thread, WAITTYPE_ARB, arbiter))
227 ResumeThreadFromWait(handle); 235 ResumeThreadFromWait(handle);
228 } 236 }
229} 237}
@@ -277,11 +285,6 @@ Thread* NextThread() {
277 return Kernel::g_object_pool.Get<Thread>(next); 285 return Kernel::g_object_pool.Get<Thread>(next);
278} 286}
279 287
280/**
281 * Puts the current thread in the wait state for the given type
282 * @param wait_type Type of wait
283 * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread
284 */
285void WaitCurrentThread(WaitType wait_type, Handle wait_handle) { 288void WaitCurrentThread(WaitType wait_type, Handle wait_handle) {
286 Thread* thread = GetCurrentThread(); 289 Thread* thread = GetCurrentThread();
287 thread->wait_type = wait_type; 290 thread->wait_type = wait_type;
@@ -289,6 +292,11 @@ void WaitCurrentThread(WaitType wait_type, Handle wait_handle) {
289 ChangeThreadState(thread, ThreadStatus(THREADSTATUS_WAIT | (thread->status & THREADSTATUS_SUSPEND))); 292 ChangeThreadState(thread, ThreadStatus(THREADSTATUS_WAIT | (thread->status & THREADSTATUS_SUSPEND)));
290} 293}
291 294
295void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_address) {
296 WaitCurrentThread(wait_type, wait_handle);
297 GetCurrentThread()->wait_address = wait_address;
298}
299
292/// Resumes a thread from waiting by marking it as "ready" 300/// Resumes a thread from waiting by marking it as "ready"
293void ResumeThreadFromWait(Handle handle) { 301void ResumeThreadFromWait(Handle handle) {
294 Thread* thread = Kernel::g_object_pool.Get<Thread>(handle); 302 Thread* thread = Kernel::g_object_pool.Get<Thread>(handle);
@@ -339,6 +347,7 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 prio
339 thread->processor_id = processor_id; 347 thread->processor_id = processor_id;
340 thread->wait_type = WAITTYPE_NONE; 348 thread->wait_type = WAITTYPE_NONE;
341 thread->wait_handle = 0; 349 thread->wait_handle = 0;
350 thread->wait_address = 0;
342 thread->name = name; 351 thread->name = name;
343 352
344 return thread; 353 return thread;