|
|
@ -49,7 +49,7 @@ use std::time::Duration; |
|
|
|
|
|
|
|
|
|
|
|
/// Thread factory, which can be used in order to configure the properties of
|
|
|
|
/// Thread factory, which can be used in order to configure the properties of
|
|
|
|
/// a new thread.
|
|
|
|
/// a new thread.
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug, Default)] |
|
|
|
pub struct Builder { |
|
|
|
pub struct Builder { |
|
|
|
// The size of the stack for the spawned thread in bytes
|
|
|
|
// The size of the stack for the spawned thread in bytes
|
|
|
|
stack_size: Option<usize>, |
|
|
|
stack_size: Option<usize>, |
|
|
@ -78,11 +78,7 @@ impl Builder { |
|
|
|
/// handler.join().unwrap();
|
|
|
|
/// handler.join().unwrap();
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub fn new() -> Builder { |
|
|
|
pub fn new() -> Builder { |
|
|
|
Builder { |
|
|
|
Self::default() |
|
|
|
stack_size: None, |
|
|
|
|
|
|
|
priority: None, |
|
|
|
|
|
|
|
affinity: None, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Sets the size of the stack (in bytes) for the new thread.
|
|
|
|
/// Sets the size of the stack (in bytes) for the new thread.
|
|
|
@ -102,6 +98,7 @@ impl Builder { |
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// [stack-size]: ./index.html#stack-size
|
|
|
|
/// [stack-size]: ./index.html#stack-size
|
|
|
|
|
|
|
|
#[must_use] |
|
|
|
pub fn stack_size(mut self, size: usize) -> Builder { |
|
|
|
pub fn stack_size(mut self, size: usize) -> Builder { |
|
|
|
self.stack_size = Some(size); |
|
|
|
self.stack_size = Some(size); |
|
|
|
self |
|
|
|
self |
|
|
@ -112,6 +109,7 @@ impl Builder { |
|
|
|
/// Low values gives the thread higher priority. For userland apps, this has
|
|
|
|
/// Low values gives the thread higher priority. For userland apps, this has
|
|
|
|
/// to be within the range of 0x18 to 0x3F inclusive. The main thread usually
|
|
|
|
/// to be within the range of 0x18 to 0x3F inclusive. The main thread usually
|
|
|
|
/// has a priority of 0x30, but not always.
|
|
|
|
/// has a priority of 0x30, but not always.
|
|
|
|
|
|
|
|
#[must_use] |
|
|
|
pub fn priority(mut self, priority: i32) -> Builder { |
|
|
|
pub fn priority(mut self, priority: i32) -> Builder { |
|
|
|
self.priority = Some(priority); |
|
|
|
self.priority = Some(priority); |
|
|
|
self |
|
|
|
self |
|
|
@ -134,6 +132,7 @@ impl Builder { |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Processes in the BASE memory region can always create threads on
|
|
|
|
/// Processes in the BASE memory region can always create threads on
|
|
|
|
/// processors #2 and #3.
|
|
|
|
/// processors #2 and #3.
|
|
|
|
|
|
|
|
#[must_use] |
|
|
|
pub fn affinity(mut self, affinity: i32) -> Builder { |
|
|
|
pub fn affinity(mut self, affinity: i32) -> Builder { |
|
|
|
self.affinity = Some(affinity); |
|
|
|
self.affinity = Some(affinity); |
|
|
|
self |
|
|
|
self |
|
|
@ -188,7 +187,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(|| imp::Thread::priority()); |
|
|
|
let priority = priority.unwrap_or_else(imp::Thread::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)
|
|
|
@ -434,6 +433,8 @@ pub fn park() { |
|
|
|
} |
|
|
|
} |
|
|
|
loop { |
|
|
|
loop { |
|
|
|
m = thread.inner.cvar.wait(m).unwrap(); |
|
|
|
m = thread.inner.cvar.wait(m).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::single_match)] |
|
|
|
match thread |
|
|
|
match thread |
|
|
|
.inner |
|
|
|
.inner |
|
|
|
.state |
|
|
|
.state |
|
|
@ -891,7 +892,6 @@ mod imp { |
|
|
|
use std::convert::TryInto; |
|
|
|
use std::convert::TryInto; |
|
|
|
use std::io; |
|
|
|
use std::io; |
|
|
|
use std::mem; |
|
|
|
use std::mem; |
|
|
|
use std::ptr; |
|
|
|
|
|
|
|
use std::time::Duration; |
|
|
|
use std::time::Duration; |
|
|
|
|
|
|
|
|
|
|
|
use libc; |
|
|
|
use libc; |
|
|
@ -929,11 +929,11 @@ mod imp { |
|
|
|
false, |
|
|
|
false, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return if handle == ptr::null_mut() { |
|
|
|
return if handle.is_null() { |
|
|
|
Err(io::Error::from_raw_os_error(libc::EAGAIN)) |
|
|
|
Err(io::Error::from_raw_os_error(libc::EAGAIN)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mem::forget(p); // ownership passed to the new thread
|
|
|
|
mem::forget(p); // ownership passed to the new thread
|
|
|
|
Ok(Thread { handle: handle }) |
|
|
|
Ok(Thread { handle }) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
extern "C" fn thread_func(start: *mut libc::c_void) { |
|
|
|
extern "C" fn thread_func(start: *mut libc::c_void) { |
|
|
|