3 use super::unsupported;
7 use crate::num::NonZeroUsize;
9 use crate::sys::hermit::abi;
10 use crate::sys::hermit::thread_local_dtor::run_dtors;
11 use crate::time::Duration;
13 pub type Tid = abi::Tid;
19 unsafe impl Send for Thread {}
20 unsafe impl Sync for Thread {}
22 pub const DEFAULT_MIN_STACK_SIZE: usize = 1 << 20;
25 pub unsafe fn new_with_coreid(
29 ) -> io::Result<Thread> {
30 let p = Box::into_raw(box p);
31 let tid = abi::spawn2(
34 abi::Priority::into(abi::NORMAL_PRIO),
40 // The thread failed to start and as a result p was not consumed. Therefore, it is
41 // safe to reconstruct the box so that it gets deallocated.
42 drop(Box::from_raw(p));
43 Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
45 Ok(Thread { tid: tid })
48 extern "C" fn thread_start(main: usize) {
50 // Finally, let's run some code.
51 Box::from_raw(ptr::from_exposed_addr::<Box<dyn FnOnce()>>(main).cast_mut())();
53 // run all destructors
59 pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
60 Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
71 pub fn set_name(_name: &CStr) {
76 pub fn sleep(dur: Duration) {
78 abi::usleep(dur.as_micros() as u64);
84 let _ = abi::join(self.tid);
89 pub fn id(&self) -> Tid {
94 pub fn into_id(self) -> Tid {
101 pub fn available_parallelism() -> io::Result<NonZeroUsize> {
107 pub unsafe fn current() -> Option<Guard> {
110 pub unsafe fn init() -> Option<Guard> {