Skip to main content

dope_uring/driver/
current.rs

1use std::cell::Cell;
2
3use super::Driver;
4
5pub type CurrentSlot = dope_core::driver::CurrentSlot<crate::UringBackend>;
6
7thread_local! {
8    static CURRENT: Cell<Option<CurrentSlot>> = const { Cell::new(None) };
9}
10
11#[inline(always)]
12pub fn set_current(slot: Option<CurrentSlot>) {
13    CURRENT.with(|cell| cell.set(slot));
14}
15
16#[inline(always)]
17pub fn current() -> Option<CurrentSlot> {
18    CURRENT.with(|cell| cell.get())
19}
20
21#[inline(always)]
22pub fn current_driver_mut<'a>() -> &'a mut Driver {
23    let slot = current()
24        .expect("dope-uring invariant violated: no current driver (called outside runtime?)");
25    unsafe { &mut *slot.driver().as_ptr() }
26}