Skip to main content

dope_sys/thread/
mod.rs

1use std::{iter, mem};
2
3use crate::{Errno, kernel::errno};
4
5pub mod signal;
6pub mod timer;
7
8pub mod affinity;
9pub mod raw;
10
11cfg_select! {
12    target_arch = "aarch64" => {
13        mod aarch64;
14        use aarch64::crc32;
15    }
16    target_arch = "x86_64" => {
17        mod x86_64;
18        use x86_64::crc32;
19    }
20    _ => {
21        mod scalar;
22        use scalar::crc32;
23    }
24}
25
26/// Smallest stack extent the C library accepts for one spawned thread.
27pub const STACK_MIN: usize = libc::PTHREAD_STACK_MIN;
28
29/// Native thread services and their backend-specific signal and timer owners.
30pub trait Thread: errno::Source {
31    type Cpus: DoubleEndedIterator<Item = affinity::raw::Cpu>
32        + ExactSizeIterator
33        + iter::FusedIterator;
34    type Timer: crate::Timer;
35    type Receiver: signal::raw::Receiver;
36
37    fn current() -> Result<Self::Cpus, affinity::Error>;
38    fn bind(cpu: affinity::raw::Cpu) -> Result<(), affinity::Error>;
39
40    /// Returns hardware admission, or None when the operating system must be queried.
41    fn crc32() -> Option<bool> {
42        crc32()
43    }
44
45    /// Initializes N caller-owned bytes from the operating system; N must not exceed 256.
46    fn entropy<const N: usize>(
47        bytes: &mut mem::MaybeUninit<[u8; N]>,
48    ) -> Result<&mut [u8; N], Errno> {
49        raw::entropy::<Self, N>(bytes)
50    }
51}