Browse Source

Move more implementation details to `imp` module

pull/10/head
Fenrir 7 years ago committed by FenrirWolf
parent
commit
86e22e59b9
  1. 55
      ctru-rs/src/thread.rs

55
ctru-rs/src/thread.rs

@ -43,8 +43,6 @@ use std::sync::atomic::Ordering::SeqCst;
use std::thread as std_thread; use std::thread as std_thread;
use std::time::Duration; use std::time::Duration;
use libctru::{svcGetProcessorID, svcGetThreadId, svcGetThreadPriority};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Builder // Builder
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -190,11 +188,7 @@ impl Builder {
// If no priority value is specified, spawn with the same // If no priority value is specified, spawn with the same
// priority as the parent thread // priority as the parent thread
let priority = priority.unwrap_or_else(|| unsafe { let priority = priority.unwrap_or_else(|| imp::Thread::priority());
let mut default_priority = 0;
svcGetThreadPriority(&mut default_priority, 0xFFFF8000);
default_priority
});
// If no affinity is specified, spawn on the default core (determined by // If no affinity is specified, spawn on the default core (determined by
// the application's Exheader) // the application's Exheader)
@ -680,28 +674,18 @@ impl Thread {
/// assert!(thread::current().id() != other_thread_id); /// assert!(thread::current().id() != other_thread_id);
/// ``` /// ```
pub fn id(&self) -> ThreadId { pub fn id(&self) -> ThreadId {
unsafe { ThreadId(imp::Thread::id())
let mut id = 0;
svcGetThreadId(&mut id, 0xFFFF8000);
ThreadId(id)
}
} }
/// Get the current thread's priority level. Lower values correspond to higher /// Get the current thread's priority level. Lower values correspond to higher
/// priority levels. The main thread's priority is typically 0x30, but not always. /// priority levels. The main thread's priority is typically 0x30, but not always.
pub fn priority(&self) -> i32 { pub fn priority(&self) -> i32 {
unsafe { imp::Thread::priority()
let mut priority = 0;
svcGetThreadPriority(&mut priority, 0xFFFF8000);
priority
}
} }
/// Returns the ID of the processor the current thread is running on. /// Returns the ID of the processor the current thread is running on.
pub fn affinity(&self) -> i32 { pub fn affinity(&self) -> i32 {
unsafe { imp::Thread::affinity()
svcGetProcessorID()
}
} }
} }
@ -911,8 +895,8 @@ mod imp {
use libc; use libc;
use libctru::{Thread as ThreadHandle, svcSleepThread, threadCreate, threadDetach, use libctru::{Thread as ThreadHandle, svcSleepThread, svcGetThreadId, svcGetThreadPriority,
threadFree, threadJoin}; svcGetProcessorID, threadCreate, threadDetach, threadFree, threadJoin};
pub struct Thread { pub struct Thread {
handle: ThreadHandle, handle: ThreadHandle,
@ -954,6 +938,28 @@ mod imp {
} }
} }
pub fn id() -> u32 {
unsafe {
let mut id = 0;
svcGetThreadId(&mut id, 0xFFFF8000);
id
}
}
pub fn priority() -> i32 {
unsafe {
let mut priority = 0;
svcGetThreadPriority(&mut priority, 0xFFFF8000);
priority
}
}
pub fn affinity() -> i32 {
unsafe {
svcGetProcessorID()
}
}
unsafe fn _start_thread(main: *mut u8) { unsafe fn _start_thread(main: *mut u8) {
Box::from_raw(main as *mut Box<FnBox()>)() Box::from_raw(main as *mut Box<FnBox()>)()
} }
@ -980,13 +986,14 @@ mod imp {
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn id(&self) -> ThreadHandle { pub fn handle(&self) -> ThreadHandle {
self.handle self.handle
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn into_id(self) -> ThreadHandle { pub fn into_handle(self) -> ThreadHandle {
let handle = self.handle; let handle = self.handle;
mem::forget(self); mem::forget(self);
handle handle

Loading…
Cancel
Save