summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2014-12-04 22:15:03 -0500
committerGravatar bunnei2014-12-04 22:15:03 -0500
commit17fae11fc7cf9392bb93dd2a1dc26a479ca75ed1 (patch)
tree5106fe8f907b9d7f8f04331cee815f25f03c0d6f
parentMerge pull request #222 from archshift/renamexyz (diff)
parentThreads: Remove a redundant function. (diff)
downloadyuzu-17fae11fc7cf9392bb93dd2a1dc26a479ca75ed1.tar.gz
yuzu-17fae11fc7cf9392bb93dd2a1dc26a479ca75ed1.tar.xz
yuzu-17fae11fc7cf9392bb93dd2a1dc26a479ca75ed1.zip
Merge pull request #250 from Subv/cbranch_2
SVC: Implemented GetThreadId.
-rw-r--r--src/core/hle/kernel/thread.cpp18
-rw-r--r--src/core/hle/kernel/thread.h8
-rw-r--r--src/core/hle/svc.cpp9
3 files changed, 31 insertions, 4 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index f59795901..8d65dc84d 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -49,6 +49,8 @@ public:
49 49
50 ThreadContext context; 50 ThreadContext context;
51 51
52 u32 thread_id;
53
52 u32 status; 54 u32 status;
53 u32 entry_point; 55 u32 entry_point;
54 u32 stack_top; 56 u32 stack_top;
@@ -76,6 +78,9 @@ static Common::ThreadQueueList<Handle> thread_ready_queue;
76static Handle current_thread_handle; 78static Handle current_thread_handle;
77static Thread* current_thread; 79static Thread* current_thread;
78 80
81static const u32 INITIAL_THREAD_ID = 1; ///< The first available thread id at startup
82static u32 next_thread_id; ///< The next available thread id
83
79/// Gets the current thread 84/// Gets the current thread
80inline Thread* GetCurrentThread() { 85inline Thread* GetCurrentThread() {
81 return current_thread; 86 return current_thread;
@@ -325,6 +330,7 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 prio
325 thread_queue.push_back(handle); 330 thread_queue.push_back(handle);
326 thread_ready_queue.prepare(priority); 331 thread_ready_queue.prepare(priority);
327 332
333 thread->thread_id = next_thread_id++;
328 thread->status = THREADSTATUS_DORMANT; 334 thread->status = THREADSTATUS_DORMANT;
329 thread->entry_point = entry_point; 335 thread->entry_point = entry_point;
330 thread->stack_top = stack_top; 336 thread->stack_top = stack_top;
@@ -465,9 +471,21 @@ void Reschedule() {
465 } 471 }
466} 472}
467 473
474ResultCode GetThreadId(u32* thread_id, Handle handle) {
475 Thread* thread = g_object_pool.Get<Thread>(handle);
476 if (thread == nullptr)
477 return ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS,
478 ErrorSummary::WrongArgument, ErrorLevel::Permanent);
479
480 *thread_id = thread->thread_id;
481
482 return RESULT_SUCCESS;
483}
484
468//////////////////////////////////////////////////////////////////////////////////////////////////// 485////////////////////////////////////////////////////////////////////////////////////////////////////
469 486
470void ThreadingInit() { 487void ThreadingInit() {
488 next_thread_id = INITIAL_THREAD_ID;
471} 489}
472 490
473void ThreadingShutdown() { 491void ThreadingShutdown() {
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index ce63a70d3..53a19d779 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -58,6 +58,14 @@ void Reschedule();
58/// Stops the current thread 58/// Stops the current thread
59ResultCode StopThread(Handle thread, const char* reason); 59ResultCode StopThread(Handle thread, const char* reason);
60 60
61/**
62 * Retrieves the ID of the specified thread handle
63 * @param thread_id Will contain the output thread id
64 * @param handle Handle to the thread we want
65 * @return Whether the function was successful or not
66 */
67ResultCode GetThreadId(u32* thread_id, Handle handle);
68
61/// Resumes a thread from waiting by marking it as "ready" 69/// Resumes a thread from waiting by marking it as "ready"
62void ResumeThreadFromWait(Handle handle); 70void ResumeThreadFromWait(Handle handle);
63 71
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 43a3cbe03..a5805ed05 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -281,10 +281,11 @@ static Result ReleaseMutex(Handle handle) {
281 return res.raw; 281 return res.raw;
282} 282}
283 283
284/// Get current thread ID 284/// Get the ID for the specified thread.
285static Result GetThreadId(u32* thread_id, Handle thread) { 285static Result GetThreadId(u32* thread_id, Handle handle) {
286 ERROR_LOG(SVC, "(UNIMPLEMENTED) called thread=0x%08X", thread); 286 DEBUG_LOG(SVC, "called thread=0x%08X", handle);
287 return 0; 287 ResultCode result = Kernel::GetThreadId(thread_id, handle);
288 return result.raw;
288} 289}
289 290
290/// Query memory 291/// Query memory