[][src]Function sunrise_kernel::scheduler::set_current_thread

unsafe fn set_current_thread<R, F: FnOnce() -> R>(
    t: Arc<ThreadStruct>,
    f: F
) -> R

Sets the current ThreadStruct.

Note that if CURRENT_THREAD was the last reference to the current thread, this is where it will be dropped.

Setting the current thread should always go through this function, and never by setting CURRENT_THREAD directly. This function uses mem::replace to ensure that the ThreadStruct's Drop is run with CURRENT_THREAD set to the new value.

The passed function will be executed after setting the CURRENT_THREAD, but before setting it back to the RUNNING state.

Unsafety

Interrupts must be disabled when calling this function. It will mutably borrow CURRENT_THREAD, so we can't have interrupts on top of that which try to access it while it is borrowed mutably by us, otherwise the kernel will panic.