diff options
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index baa9687cb..ab5a5559e 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -154,26 +154,23 @@ inline bool VerifyWait(const Handle& handle, WaitType type, Handle wait_handle) | |||
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | /// Stops the current thread | 156 | /// Stops the current thread |
| 157 | void StopThread(Handle thread, const char* reason) { | 157 | void StopThread(Handle handle, const char* reason) { |
| 158 | u32 error; | 158 | Thread* thread = g_object_pool.GetFast<Thread>(handle); |
| 159 | Thread* t = g_object_pool.Get<Thread>(thread, error); | 159 | _assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!"); |
| 160 | if (t) { | 160 | |
| 161 | ChangeReadyState(t, false); | 161 | ChangeReadyState(thread, false); |
| 162 | t->status = THREADSTATUS_DORMANT; | 162 | thread->status = THREADSTATUS_DORMANT; |
| 163 | for (size_t i = 0; i < t->waiting_threads.size(); ++i) { | 163 | for (size_t i = 0; i < thread->waiting_threads.size(); ++i) { |
| 164 | const Handle waiting_thread = t->waiting_threads[i]; | 164 | const Handle waiting_thread = thread->waiting_threads[i]; |
| 165 | if (VerifyWait(waiting_thread, WAITTYPE_THREADEND, thread)) { | 165 | if (VerifyWait(waiting_thread, WAITTYPE_THREADEND, handle)) { |
| 166 | ResumeThreadFromWait(waiting_thread); | 166 | ResumeThreadFromWait(waiting_thread); |
| 167 | } | ||
| 168 | } | 167 | } |
| 169 | t->waiting_threads.clear(); | ||
| 170 | |||
| 171 | // Stopped threads are never waiting. | ||
| 172 | t->wait_type = WAITTYPE_NONE; | ||
| 173 | t->wait_handle = 0; | ||
| 174 | } else { | ||
| 175 | ERROR_LOG(KERNEL, "thread 0x%08X does not exist", thread); | ||
| 176 | } | 168 | } |
| 169 | thread->waiting_threads.clear(); | ||
| 170 | |||
| 171 | // Stopped threads are never waiting. | ||
| 172 | thread->wait_type = WAITTYPE_NONE; | ||
| 173 | thread->wait_handle = 0; | ||
| 177 | } | 174 | } |
| 178 | 175 | ||
| 179 | /// Changes a threads state | 176 | /// Changes a threads state |
| @@ -242,20 +239,20 @@ Thread* NextThread() { | |||
| 242 | 239 | ||
| 243 | /// Puts the current thread in the wait state for the given type | 240 | /// Puts the current thread in the wait state for the given type |
| 244 | void WaitCurrentThread(WaitType wait_type, Handle wait_handle) { | 241 | void WaitCurrentThread(WaitType wait_type, Handle wait_handle) { |
| 245 | Thread* t = GetCurrentThread(); | 242 | Thread* thread = GetCurrentThread(); |
| 246 | t->wait_type = wait_type; | 243 | thread->wait_type = wait_type; |
| 247 | t->wait_handle = wait_handle; | 244 | thread->wait_handle = wait_handle; |
| 248 | ChangeThreadState(t, ThreadStatus(THREADSTATUS_WAIT | (t->status & THREADSTATUS_SUSPEND))); | 245 | ChangeThreadState(thread, ThreadStatus(THREADSTATUS_WAIT | (thread->status & THREADSTATUS_SUSPEND))); |
| 249 | } | 246 | } |
| 250 | 247 | ||
| 251 | /// Resumes a thread from waiting by marking it as "ready" | 248 | /// Resumes a thread from waiting by marking it as "ready" |
| 252 | void ResumeThreadFromWait(Handle handle) { | 249 | void ResumeThreadFromWait(Handle handle) { |
| 253 | u32 error; | 250 | u32 error; |
| 254 | Thread* t = Kernel::g_object_pool.Get<Thread>(handle, error); | 251 | Thread* thread = Kernel::g_object_pool.Get<Thread>(handle, error); |
| 255 | if (t) { | 252 | if (thread) { |
| 256 | t->status &= ~THREADSTATUS_WAIT; | 253 | thread->status &= ~THREADSTATUS_WAIT; |
| 257 | if (!(t->status & (THREADSTATUS_WAITSUSPEND | THREADSTATUS_DORMANT | THREADSTATUS_DEAD))) { | 254 | if (!(thread->status & (THREADSTATUS_WAITSUSPEND | THREADSTATUS_DORMANT | THREADSTATUS_DEAD))) { |
| 258 | ChangeReadyState(t, true); | 255 | ChangeReadyState(thread, true); |
| 259 | } | 256 | } |
| 260 | } | 257 | } |
| 261 | } | 258 | } |
| @@ -283,26 +280,26 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 prio | |||
| 283 | _assert_msg_(KERNEL, (priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST), | 280 | _assert_msg_(KERNEL, (priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST), |
| 284 | "CreateThread priority=%d, outside of allowable range!", priority) | 281 | "CreateThread priority=%d, outside of allowable range!", priority) |
| 285 | 282 | ||
| 286 | Thread* t = new Thread; | 283 | Thread* thread = new Thread; |
| 287 | 284 | ||
| 288 | handle = Kernel::g_object_pool.Create(t); | 285 | handle = Kernel::g_object_pool.Create(thread); |
| 289 | 286 | ||
| 290 | g_thread_queue.push_back(handle); | 287 | g_thread_queue.push_back(handle); |
| 291 | g_thread_ready_queue.prepare(priority); | 288 | g_thread_ready_queue.prepare(priority); |
| 292 | 289 | ||
| 293 | t->status = THREADSTATUS_DORMANT; | 290 | thread->status = THREADSTATUS_DORMANT; |
| 294 | t->entry_point = entry_point; | 291 | thread->entry_point = entry_point; |
| 295 | t->stack_top = stack_top; | 292 | thread->stack_top = stack_top; |
| 296 | t->stack_size = stack_size; | 293 | thread->stack_size = stack_size; |
| 297 | t->initial_priority = t->current_priority = priority; | 294 | thread->initial_priority = thread->current_priority = priority; |
| 298 | t->processor_id = processor_id; | 295 | thread->processor_id = processor_id; |
| 299 | t->wait_type = WAITTYPE_NONE; | 296 | thread->wait_type = WAITTYPE_NONE; |
| 300 | t->wait_handle = 0; | 297 | thread->wait_handle = 0; |
| 301 | 298 | ||
| 302 | strncpy(t->name, name, Kernel::MAX_NAME_LENGTH); | 299 | strncpy(thread->name, name, Kernel::MAX_NAME_LENGTH); |
| 303 | t->name[Kernel::MAX_NAME_LENGTH] = '\0'; | 300 | thread->name[Kernel::MAX_NAME_LENGTH] = '\0'; |
| 304 | 301 | ||
| 305 | return t; | 302 | return thread; |
| 306 | } | 303 | } |
| 307 | 304 | ||
| 308 | /// Creates a new thread - wrapper for external user | 305 | /// Creates a new thread - wrapper for external user |
| @@ -331,11 +328,11 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3 | |||
| 331 | return -1; | 328 | return -1; |
| 332 | } | 329 | } |
| 333 | Handle handle; | 330 | Handle handle; |
| 334 | Thread* t = CreateThread(handle, name, entry_point, priority, processor_id, stack_top, | 331 | Thread* thread = CreateThread(handle, name, entry_point, priority, processor_id, stack_top, |
| 335 | stack_size); | 332 | stack_size); |
| 336 | 333 | ||
| 337 | ResetThread(t, arg, 0); | 334 | ResetThread(thread, arg, 0); |
| 338 | CallThread(t); | 335 | CallThread(thread); |
| 339 | 336 | ||
| 340 | return handle; | 337 | return handle; |
| 341 | } | 338 | } |
| @@ -388,10 +385,10 @@ Handle SetupMainThread(s32 priority, int stack_size) { | |||
| 388 | Handle handle; | 385 | Handle handle; |
| 389 | 386 | ||
| 390 | // Initialize new "main" thread | 387 | // Initialize new "main" thread |
| 391 | Thread* t = CreateThread(handle, "main", Core::g_app_core->GetPC(), priority, | 388 | Thread* thread = CreateThread(handle, "main", Core::g_app_core->GetPC(), priority, |
| 392 | THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END, stack_size); | 389 | THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END, stack_size); |
| 393 | 390 | ||
| 394 | ResetThread(t, 0, 0); | 391 | ResetThread(thread, 0, 0); |
| 395 | 392 | ||
| 396 | // If running another thread already, set it to "ready" state | 393 | // If running another thread already, set it to "ready" state |
| 397 | Thread* cur = GetCurrentThread(); | 394 | Thread* cur = GetCurrentThread(); |
| @@ -400,9 +397,9 @@ Handle SetupMainThread(s32 priority, int stack_size) { | |||
| 400 | } | 397 | } |
| 401 | 398 | ||
| 402 | // Run new "main" thread | 399 | // Run new "main" thread |
| 403 | SetCurrentThread(t); | 400 | SetCurrentThread(thread); |
| 404 | t->status = THREADSTATUS_RUNNING; | 401 | thread->status = THREADSTATUS_RUNNING; |
| 405 | LoadContext(t->context); | 402 | LoadContext(thread->context); |
| 406 | 403 | ||
| 407 | return handle; | 404 | return handle; |
| 408 | } | 405 | } |