#[derive(Debug, Clone, PartialEq)]
pub struct ThreadAllocationInput {
pub physical: usize,
pub logical: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ThreadAllocationOutput {
pub name: Option<String>,
pub ident: usize,
pub stack_size: Option<usize>,
pub affinity: Option<usize>,
}
pub fn thread_info() -> ThreadAllocationInput {
ThreadAllocationInput {
logical: num_cpus::get(),
physical: num_cpus::get_physical(),
}
}
pub fn single_thread(
thread_name: Option<String>,
affinity: Option<usize>,
) -> impl Iterator<Item = ThreadAllocationOutput> {
std::iter::once(ThreadAllocationOutput {
name: thread_name,
ident: 0,
stack_size: None,
affinity,
})
}
#[allow(clippy::needless_lifetimes)]
pub fn one_to_one<'a>(
input: ThreadAllocationInput,
thread_name: Option<&'a str>,
) -> impl Iterator<Item = ThreadAllocationOutput> + 'a {
(0..input.logical).map(move |idx| ThreadAllocationOutput {
name: thread_name.map(ToOwned::to_owned),
ident: idx,
stack_size: None,
affinity: Some(idx),
})
}
#[allow(clippy::needless_lifetimes)]
pub fn two_to_one<'a>(
input: ThreadAllocationInput,
thread_name: Option<&'a str>,
) -> impl Iterator<Item = ThreadAllocationOutput> + 'a {
(0..(input.logical * 2)).map(move |idx| ThreadAllocationOutput {
name: thread_name.map(ToOwned::to_owned),
ident: idx,
stack_size: None,
affinity: Some(idx / 2),
})
}