summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index f2094f7a7..c84fdf91d 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -294,6 +294,51 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3
294 return handle; 294 return handle;
295} 295}
296 296
297/// Get the priority of the thread specified by handle
298u32 GetThreadPriority(const Handle handle) {
299 Thread* thread = g_object_pool.GetFast<Thread>(handle);
300 _assert_msg_(KERNEL, thread, "called, but thread is NULL!");
301 return thread->current_priority;
302}
303
304/// Set the priority of the thread specified by handle
305Result SetThreadPriority(Handle handle, s32 priority) {
306 Thread* thread = NULL;
307 if (!handle) {
308 thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior?
309 } else {
310 thread = g_object_pool.GetFast<Thread>(handle);
311 }
312 _assert_msg_(KERNEL, thread, "called, but thread is NULL!");
313
314 // If priority is invalid, clamp to valid range
315 if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
316 s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
317 WARN_LOG(KERNEL, "invalid priority=0x%08X, clamping to %08X", priority, new_priority);
318 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
319 // validity of this
320 priority = new_priority;
321 }
322
323 // Change thread priority
324 s32 old = thread->current_priority;
325 g_thread_ready_queue.remove(old, handle);
326 thread->current_priority = priority;
327 g_thread_ready_queue.prepare(thread->current_priority);
328
329 // Change thread status to "ready" and push to ready queue
330 if (thread->IsRunning()) {
331 thread->status = (thread->status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY;
332 }
333 if (thread->IsReady()) {
334 g_thread_ready_queue.push_back(thread->current_priority, handle);
335 }
336
337 HLE::EatCycles(450);
338
339 return 0;
340}
341
297/// Sets up the primary application thread 342/// Sets up the primary application thread
298Handle SetupMainThread(s32 priority, int stack_size) { 343Handle SetupMainThread(s32 priority, int stack_size) {
299 Handle handle; 344 Handle handle;