use std::cell::Cell;
use super::Driver;
pub type CurrentSlot = dope_core::driver::CurrentSlot<crate::KqueueBackend>;
thread_local! {
static CURRENT: Cell<Option<CurrentSlot>> = const { Cell::new(None) };
}
pub fn set_current(slot: Option<CurrentSlot>) {
CURRENT.with(|cell| cell.set(slot));
}
pub fn current() -> Option<CurrentSlot> {
CURRENT.with(|cell| cell.get())
}
pub(crate) fn current_driver_mut_ptr() -> *mut Driver {
CURRENT.with(|cell| match cell.get() {
Some(slot) => slot.driver().as_ptr(),
None => std::ptr::null_mut(),
})
}
pub fn current_driver_mut<'a>() -> &'a mut Driver {
let p = current_driver_mut_ptr();
assert!(
!p.is_null(),
"dope-kqueue invariant violated: no current driver"
);
unsafe { &mut *p }
}