ostd/task/preempt/
guard.rs1use crate::{sync::GuardTransfer, task::atomic_mode::InAtomicMode};
4
5#[clippy::has_significant_drop]
7#[must_use]
8#[derive(Debug)]
9pub struct DisabledPreemptGuard {
10 _private: (),
12}
13
14impl !Send for DisabledPreemptGuard {}
15
16unsafe impl InAtomicMode for DisabledPreemptGuard {}
19
20impl DisabledPreemptGuard {
21 fn new() -> Self {
22 super::cpu_local::inc_guard_count();
23 Self { _private: () }
24 }
25}
26
27impl GuardTransfer for DisabledPreemptGuard {
28 fn transfer_to(&mut self) -> Self {
29 disable_preempt()
30 }
31}
32
33impl Drop for DisabledPreemptGuard {
34 fn drop(&mut self) {
35 super::cpu_local::dec_guard_count();
36 }
37}
38
39pub fn disable_preempt() -> DisabledPreemptGuard {
41 DisabledPreemptGuard::new()
42}