diff options
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 16 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 7 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 6da238828..ccb927381 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -78,6 +78,17 @@ static Common::ThreadQueueList<Handle> thread_ready_queue; | |||
| 78 | static Handle current_thread_handle; | 78 | static Handle current_thread_handle; |
| 79 | static Thread* current_thread; | 79 | static Thread* current_thread; |
| 80 | 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 | |||
| 84 | /** | ||
| 85 | * Gets the next available thread id and increments it | ||
| 86 | * @return Next available thread id | ||
| 87 | */ | ||
| 88 | static u32 NextThreadId() { | ||
| 89 | return next_thread_id++; | ||
| 90 | } | ||
| 91 | |||
| 81 | /// Gets the current thread | 92 | /// Gets the current thread |
| 82 | inline Thread* GetCurrentThread() { | 93 | inline Thread* GetCurrentThread() { |
| 83 | return current_thread; | 94 | return current_thread; |
| @@ -327,9 +338,7 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 prio | |||
| 327 | thread_queue.push_back(handle); | 338 | thread_queue.push_back(handle); |
| 328 | thread_ready_queue.prepare(priority); | 339 | thread_ready_queue.prepare(priority); |
| 329 | 340 | ||
| 330 | // TODO(Subv): Assign valid ids to each thread, they are much lower than handle values | 341 | thread->thread_id = NextThreadId(); |
| 331 | // they appear to begin at 276 and continue from there | ||
| 332 | thread->thread_id = handle; | ||
| 333 | thread->status = THREADSTATUS_DORMANT; | 342 | thread->status = THREADSTATUS_DORMANT; |
| 334 | thread->entry_point = entry_point; | 343 | thread->entry_point = entry_point; |
| 335 | thread->stack_top = stack_top; | 344 | thread->stack_top = stack_top; |
| @@ -484,6 +493,7 @@ ResultCode GetThreadId(u32* thread_id, Handle handle) { | |||
| 484 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 493 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 485 | 494 | ||
| 486 | void ThreadingInit() { | 495 | void ThreadingInit() { |
| 496 | next_thread_id = INITIAL_THREAD_ID; | ||
| 487 | } | 497 | } |
| 488 | 498 | ||
| 489 | void ThreadingShutdown() { | 499 | void ThreadingShutdown() { |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index e87867ac0..53a19d779 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -58,7 +58,12 @@ 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 | // Retrieves the thread id of the specified thread handle | 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 | */ | ||
| 62 | ResultCode GetThreadId(u32* thread_id, Handle handle); | 67 | ResultCode GetThreadId(u32* thread_id, Handle handle); |
| 63 | 68 | ||
| 64 | /// Resumes a thread from waiting by marking it as "ready" | 69 | /// Resumes a thread from waiting by marking it as "ready" |