use crate::cpu_local_cell;
pub(in crate::task) fn should_preempt() -> bool {
PREEMPT_INFO.load() == 0
}
pub(in crate::task) fn need_preempt() -> bool {
PREEMPT_INFO.load() & NEED_PREEMPT_MASK == 0
}
pub(in crate::task) fn set_need_preempt() {
PREEMPT_INFO.bitand_assign(!NEED_PREEMPT_MASK);
}
pub(in crate::task) fn clear_need_preempt() {
PREEMPT_INFO.bitor_assign(NEED_PREEMPT_MASK);
}
pub(in crate::task) fn get_guard_count() -> u32 {
PREEMPT_INFO.load() & GUARD_COUNT_MASK
}
pub(in crate::task) fn inc_guard_count() {
PREEMPT_INFO.add_assign(1);
}
pub(in crate::task) fn dec_guard_count() {
debug_assert!(get_guard_count() > 0);
PREEMPT_INFO.sub_assign(1);
}
cpu_local_cell! {
static PREEMPT_INFO: u32 = NEED_PREEMPT_MASK;
}
const NEED_PREEMPT_MASK: u32 = 1 << 31;
const GUARD_COUNT_MASK: u32 = (1 << 31) - 1;