3 use super::unsupported;
7 use crate::num::NonZeroUsize;
8 use crate::sys::hermit::abi;
9 use crate::sys::hermit::thread_local_dtor::run_dtors;
10 use crate::time::Duration;
12 pub type Tid = abi::Tid;
18 unsafe impl Send for Thread {}
19 unsafe impl Sync for Thread {}
21 pub const DEFAULT_MIN_STACK_SIZE: usize = 1 << 20;
24 pub unsafe fn new_with_coreid(
28 ) -> io::Result<Thread> {
29 let p = Box::into_raw(box p);
30 let tid = abi::spawn2(
33 abi::Priority::into(abi::NORMAL_PRIO),
39 // The thread failed to start and as a result p was not consumed. Therefore, it is
40 // safe to reconstruct the box so that it gets deallocated.
41 drop(Box::from_raw(p));
42 Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
44 Ok(Thread { tid: tid })
47 extern "C" fn thread_start(main: usize) {
49 // Finally, let's run some code.
50 Box::from_raw(main as *mut Box<dyn FnOnce()>)();
52 // run all destructors
58 pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
59 Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
70 pub fn set_name(_name: &CStr) {
75 pub fn sleep(dur: Duration) {
77 abi::usleep(dur.as_micros() as u64);
83 let _ = abi::join(self.tid);
88 pub fn id(&self) -> Tid {
93 pub fn into_id(self) -> Tid {
100 pub fn available_parallelism() -> io::Result<NonZeroUsize> {
106 pub unsafe fn current() -> Option<Guard> {
109 pub unsafe fn init() -> Option<Guard> {