summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp29
-rw-r--r--src/core/hle/kernel/thread.h11
3 files changed, 31 insertions, 11 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index db571b895..ce4f3c854 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -53,7 +53,7 @@ ResultCode ArbitrateAddress(Handle handle, ArbitrationType type, u32 address, s3
53 // Wait current thread (acquire the arbiter)... 53 // Wait current thread (acquire the arbiter)...
54 case ArbitrationType::WaitIfLessThan: 54 case ArbitrationType::WaitIfLessThan:
55 if ((s32)Memory::Read32(address) <= value) { 55 if ((s32)Memory::Read32(address) <= value) {
56 Kernel::WaitCurrentThread(WAITTYPE_ARB, handle); 56 Kernel::WaitCurrentThread(WAITTYPE_ARB, handle, address);
57 HLE::Reschedule(__func__); 57 HLE::Reschedule(__func__);
58 } 58 }
59 break; 59 break;
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;
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 53a19d779..be7adface 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -5,6 +5,9 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8
9#include "core/mem_map.h"
10
8#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/kernel.h"
9#include "core/hle/result.h" 12#include "core/hle/result.h"
10 13
@@ -85,6 +88,14 @@ Handle GetCurrentThreadHandle();
85 */ 88 */
86void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle()); 89void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle());
87 90
91/**
92 * Puts the current thread in the wait state for the given type
93 * @param wait_type Type of wait
94 * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread
95 * @param wait_address Arbitration address used to resume from wait
96 */
97void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_address);
98
88/// Put current thread in a wait state - on WaitSynchronization 99/// Put current thread in a wait state - on WaitSynchronization
89void WaitThread_Synchronization(); 100void WaitThread_Synchronization();
90 101