6 use crate::sys::hermit::abi;
7 use crate::sys::hermit::fast_thread_local::run_dtors;
8 use crate::time::Duration;
10 pub type Tid = abi::Tid;
16 unsafe impl Send for Thread {}
17 unsafe impl Sync for Thread {}
19 pub const DEFAULT_MIN_STACK_SIZE: usize = 1 << 20;
22 pub unsafe fn new_with_coreid(
26 ) -> io::Result<Thread> {
27 let p = Box::into_raw(box p);
28 let tid = abi::spawn2(
31 abi::Priority::into(abi::NORMAL_PRIO),
37 // The thread failed to start and as a result p was not consumed. Therefore, it is
38 // safe to reconstruct the box so that it gets deallocated.
39 drop(Box::from_raw(p));
40 Err(io::Error::new(io::ErrorKind::Other, "Unable to create thread!"))
42 Ok(Thread { tid: tid })
45 extern "C" fn thread_start(main: usize) {
47 // Finally, let's run some code.
48 Box::from_raw(main as *mut Box<dyn FnOnce()>)();
50 // run all destructors
56 pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
57 Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
68 pub fn set_name(_name: &CStr) {
73 pub fn sleep(dur: Duration) {
75 abi::usleep(dur.as_micros() as u64);
81 let _ = abi::join(self.tid);
86 pub fn id(&self) -> Tid {
91 pub fn into_id(self) -> Tid {
100 pub unsafe fn current() -> Option<Guard> {
103 pub unsafe fn init() -> Option<Guard> {