diff options
| author | Fenrir <[email protected]> | 2017-03-05 23:41:03 -0700 |
|---|---|---|
| committer | Fenrir <[email protected]> | 2017-03-05 23:42:41 -0700 |
| commit | 5df46967631051efcb5143e3a4cb6afe6b77f67d (patch) | |
| tree | a6d528557aeee7b077745d16bbd96405703b07db /ctr-std/src/sys | |
| parent | Add the rest of std::sync (diff) | |
| download | ctru-rs-5df46967631051efcb5143e3a4cb6afe6b77f67d.tar.xz ctru-rs-5df46967631051efcb5143e3a4cb6afe6b77f67d.zip | |
Ensure child threads have higher priority than main
Diffstat (limited to 'ctr-std/src/sys')
| -rw-r--r-- | ctr-std/src/sys/unix/thread.rs | 11 |
1 files 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)) |