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
16impl !Sync for DisabledPreemptGuard {}
18
19unsafe impl InAtomicMode for DisabledPreemptGuard {}
23
24impl DisabledPreemptGuard {
25 fn new() -> Self {
26 super::cpu_local::inc_guard_count();
27 Self { _private: () }
28 }
29}
30
31impl GuardTransfer for DisabledPreemptGuard {
32 fn transfer_to(&mut self) -> Self {
33 disable_preempt()
34 }
35}
36
37impl Drop for DisabledPreemptGuard {
38 fn drop(&mut self) {
39 super::cpu_local::dec_guard_count();
40 }
41}
42
43pub fn disable_preempt() -> DisabledPreemptGuard {
45 DisabledPreemptGuard::new()
46}