1#[derive(Debug, Clone, PartialEq)]
6pub struct ThreadAllocationInput {
7 pub physical: usize,
9 pub logical: usize,
11}
12
13#[derive(Debug, Clone, PartialEq)]
15pub struct ThreadAllocationOutput {
16 pub name: Option<String>,
18 pub ident: usize,
20 pub stack_size: Option<usize>,
22 pub affinity: Option<usize>,
25}
26
27pub fn thread_info() -> ThreadAllocationInput {
29 ThreadAllocationInput {
30 logical: num_cpus::get(),
31 physical: num_cpus::get_physical(),
32 }
33}
34
35pub fn single_thread(
39 thread_name: Option<String>,
40 affinity: Option<usize>,
41) -> impl Iterator<Item = ThreadAllocationOutput> {
42 std::iter::once(ThreadAllocationOutput {
43 name: thread_name,
44 ident: 0,
45 stack_size: None,
46 affinity,
47 })
48}
49
50#[allow(clippy::needless_lifetimes)]
57pub fn one_to_one<'a>(
58 input: ThreadAllocationInput,
59 thread_name: Option<&'a str>,
60) -> impl Iterator<Item = ThreadAllocationOutput> + 'a {
61 (0..input.logical).map(move |idx| ThreadAllocationOutput {
62 name: thread_name.map(ToOwned::to_owned),
63 ident: idx,
64 stack_size: None,
65 affinity: Some(idx),
66 })
67}
68
69#[allow(clippy::needless_lifetimes)]
76pub fn two_to_one<'a>(
77 input: ThreadAllocationInput,
78 thread_name: Option<&'a str>,
79) -> impl Iterator<Item = ThreadAllocationOutput> + 'a {
80 (0..(input.logical * 2)).map(move |idx| ThreadAllocationOutput {
81 name: thread_name.map(ToOwned::to_owned),
82 ident: idx,
83 stack_size: None,
84 affinity: Some(idx / 2),
85 })
86}