summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2014-07-06 22:48:19 -0400
committerGravatar bunnei2014-07-08 18:46:15 -0400
commitba840d3200183e30a5d85acf494d2a6bbbb3a386 (patch)
treedb48fcff1aa64ce648af51934a0c226646d2c3be /src
parentfunction_wrappers: Fixed incorrect wrapper, added another. (diff)
downloadyuzu-ba840d3200183e30a5d85acf494d2a6bbbb3a386.tar.gz
yuzu-ba840d3200183e30a5d85acf494d2a6bbbb3a386.tar.xz
yuzu-ba840d3200183e30a5d85acf494d2a6bbbb3a386.zip
Thread: Added functions to resume threads from address arbitration.
Thread: Cleaned up arbitrate address functions. Thread: Cleaned up ArbitrateAllThreads function.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/thread.cpp37
-rw-r--r--src/core/hle/kernel/thread.h7
2 files changed, 44 insertions, 0 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index ab5a5559e..86bbf29d0 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -188,6 +188,43 @@ void ChangeThreadState(Thread* t, ThreadStatus new_status) {
188 } 188 }
189} 189}
190 190
191/// Arbitrate the highest priority thread that is waiting
192Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address) {
193 Handle highest_priority_thread = 0;
194 s32 priority = THREADPRIO_LOWEST;
195
196 // Iterate through threads, find highest priority thread that is waiting to be arbitrated...
197 for (const auto& handle : g_thread_queue) {
198
199 // TODO(bunnei): Verify arbiter address...
200 if (!VerifyWait(handle, WAITTYPE_ARB, arbiter))
201 continue;
202
203 Thread* thread = g_object_pool.GetFast<Thread>(handle);
204 if(thread->current_priority <= priority) {
205 highest_priority_thread = handle;
206 priority = thread->current_priority;
207 }
208 }
209 // If a thread was arbitrated, resume it
210 if (0 != highest_priority_thread)
211 ResumeThreadFromWait(highest_priority_thread);
212
213 return highest_priority_thread;
214}
215
216/// Arbitrate all threads currently waiting
217void ArbitrateAllThreads(u32 arbiter, u32 address) {
218
219 // Iterate through threads, find highest priority thread that is waiting to be arbitrated...
220 for (const auto& handle : g_thread_queue) {
221
222 // TODO(bunnei): Verify arbiter address...
223 if (VerifyWait(handle, WAITTYPE_ARB, arbiter))
224 ResumeThreadFromWait(handle);
225 }
226}
227
191/// Calls a thread by marking it as "ready" (note: will not actually execute until current thread yields) 228/// Calls a thread by marking it as "ready" (note: will not actually execute until current thread yields)
192void CallThread(Thread* t) { 229void CallThread(Thread* t) {
193 // Stop waiting 230 // Stop waiting
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 04914ba90..f2bfdfa1a 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -39,6 +39,7 @@ enum WaitType {
39 WAITTYPE_VBLANK, 39 WAITTYPE_VBLANK,
40 WAITTYPE_MUTEX, 40 WAITTYPE_MUTEX,
41 WAITTYPE_SYNCH, 41 WAITTYPE_SYNCH,
42 WAITTYPE_ARB,
42}; 43};
43 44
44namespace Kernel { 45namespace Kernel {
@@ -59,6 +60,12 @@ void StopThread(Handle thread, const char* reason);
59/// Resumes a thread from waiting by marking it as "ready" 60/// Resumes a thread from waiting by marking it as "ready"
60void ResumeThreadFromWait(Handle handle); 61void ResumeThreadFromWait(Handle handle);
61 62
63/// Arbitrate the highest priority thread that is waiting
64Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address);
65
66/// Arbitrate all threads currently waiting...
67void ArbitrateAllThreads(u32 arbiter, u32 address);
68
62/// Gets the current thread handle 69/// Gets the current thread handle
63Handle GetCurrentThreadHandle(); 70Handle GetCurrentThreadHandle();
64 71