From 5df46967631051efcb5143e3a4cb6afe6b77f67d Mon Sep 17 00:00:00 2001 From: Fenrir Date: Sun, 5 Mar 2017 23:41:03 -0700 Subject: [PATCH] Ensure child threads have higher priority than main --- ctr-std/src/sys/unix/thread.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ctr-std/src/sys/unix/thread.rs b/ctr-std/src/sys/unix/thread.rs index 4eac345..f100f3d 100644 --- a/ctr-std/src/sys/unix/thread.rs +++ b/ctr-std/src/sys/unix/thread.rs @@ -18,7 +18,7 @@ use ptr; use sys_common::thread::start_thread; use time::Duration; -use libctru::svc::svcSleepThread; +use libctru::svc::{svcSleepThread, svcGetThreadPriority}; use libctru::thread::{threadCreate, threadJoin, threadFree}; use libctru::thread::Thread as ThreadHandle; @@ -36,8 +36,15 @@ impl Thread { let p = box p; let stack_size = cmp::max(stack, 4 * 1024); + // this retrieves the main thread's priority value. child threads need + // to be spawned with a greater priority (smaller priority value) than + // the main thread + let mut priority = 0; + svcGetThreadPriority(&mut priority, 0xFFFF8000); + priority -= 1; + let handle = threadCreate(Some(thread_func), &*p as *const _ as *mut _, - stack_size, 0x29, -2, 0); + stack_size, priority, -2, 0); return if handle == ptr::null_mut() { Err(io::Error::from_raw_os_error(libc::EAGAIN))