use crate::ffi::CStr;
use crate::io;
use crate::num::NonZeroUsize;
use crate::time::Duration;

pub struct Thread(!);

pub const DEFAULT_MIN_STACK_SIZE: usize = 8192;

impl Thread {
    pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>) -> io::Result<Thread> {
        yggdrasil_rt::sys::debug_trace("Thread::new()");
        loop {}
    }

    pub fn yield_now() {
        unsafe {
            yggdrasil_rt::sys::debug_trace("Thread::yield_now()");
        }
    }

    pub fn set_name(_name: &CStr) {
        unsafe {
            yggdrasil_rt::sys::debug_trace("Thread::set_name()");
        }
    }

    pub fn sleep(dur: Duration) {
        unsafe { yggdrasil_rt::sys::nanosleep(dur) }
    }

    pub fn join(self) {
        unsafe {
            yggdrasil_rt::sys::debug_trace("Thread::join()");
        }
        loop {}
    }
}

pub fn available_parallelism() -> io::Result<NonZeroUsize> {
    unsafe {
        yggdrasil_rt::sys::debug_trace("thread::available_parallelism()");
    }
    loop {}
}

pub mod guard {
    pub type Guard = !;

    pub unsafe fn current() -> Option<Guard> {
        None
    }

    pub unsafe fn init() -> Option<Guard> {
        None
    }
}
