diff options
| author | 2014-12-04 22:15:03 -0500 | |
|---|---|---|
| committer | 2014-12-04 22:15:03 -0500 | |
| commit | 17fae11fc7cf9392bb93dd2a1dc26a479ca75ed1 (patch) | |
| tree | 5106fe8f907b9d7f8f04331cee815f25f03c0d6f | |
| parent | Merge pull request #222 from archshift/renamexyz (diff) | |
| parent | Threads: Remove a redundant function. (diff) | |
| download | yuzu-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.cpp | 18 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 8 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 9 |
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; | |||
| 76 | static Handle current_thread_handle; | 78 | static Handle current_thread_handle; |
| 77 | static Thread* current_thread; | 79 | static Thread* current_thread; |
| 78 | 80 | ||
| 81 | static const u32 INITIAL_THREAD_ID = 1; ///< The first available thread id at startup | ||
| 82 | static u32 next_thread_id; ///< The next available thread id | ||
| 83 | |||
| 79 | /// Gets the current thread | 84 | /// Gets the current thread |
| 80 | inline Thread* GetCurrentThread() { | 85 | inline 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 | ||
| 474 | ResultCode 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 | ||
| 470 | void ThreadingInit() { | 487 | void ThreadingInit() { |
| 488 | next_thread_id = INITIAL_THREAD_ID; | ||
| 471 | } | 489 | } |
| 472 | 490 | ||
| 473 | void ThreadingShutdown() { | 491 | void 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 |
| 59 | ResultCode StopThread(Handle thread, const char* reason); | 59 | ResultCode 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 | */ | ||
| 67 | ResultCode 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" |
| 62 | void ResumeThreadFromWait(Handle handle); | 70 | void 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. |
| 285 | static Result GetThreadId(u32* thread_id, Handle thread) { | 285 | static 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 |