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;
9mod attrs;
10mod handle;
11pub mod raw;
12
13pub use attrs::Attrs;
14pub use handle::Handle;
15
16/// Smallest stack extent the C library accepts for one spawned thread.
17pub const STACK_MIN: usize = libc::PTHREAD_STACK_MIN;
18
19/// Native thread services and their backend-specific signal and timer owners.
20pub trait Thread: errno::Source {
21    type Cpus: DoubleEndedIterator<Item = affinity::raw::Cpu>
22        + ExactSizeIterator
23        + iter::FusedIterator;
24    type Timer: crate::Timer;
25    type Receiver: signal::raw::Receiver;
26
27    fn current() -> Result<Self::Cpus, affinity::Error>;
28    fn bind(cpu: affinity::raw::Cpu) -> Result<(), affinity::Error>;
29
30    /// Returns whether the caller is the process's original thread.
31    fn is_main() -> bool;
32
33    /// Admits the native IEEE CRC32 backend without shared feature state.
34    /// A denied native query retains its exact errno; callers may use software CRC.
35    fn try_crc32() -> Result<bool, Errno> {
36        raw::try_crc32(Self::read)
37    }
38
39    /// Initializes N caller-owned bytes from the operating system; N must not exceed 256.
40    fn entropy<const N: usize>(
41        bytes: &mut mem::MaybeUninit<[u8; N]>,
42    ) -> Result<&mut [u8; N], Errno> {
43        raw::entropy::<Self, N>(bytes)
44    }
45}