Introduce the semantics of the atomic-mode guard

This commit is contained in:
Chen Chengjun
2025-03-25 22:04:10 +08:00
committed by Ruihan Li
parent 7a8afd8c48
commit 208d5aa62d
4 changed files with 43 additions and 12 deletions

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use crate::sync::GuardTransfer;
use crate::{sync::GuardTransfer, task::atomic_mode::InAtomicMode};
/// A guard for disable preempt.
#[clippy::has_significant_drop]
@ -13,6 +13,10 @@ pub struct DisabledPreemptGuard {
impl !Send for DisabledPreemptGuard {}
// SAFETY: The guard disables preemptions, which meets the second
// sufficient condition for atomic mode.
unsafe impl InAtomicMode for DisabledPreemptGuard {}
impl DisabledPreemptGuard {
fn new() -> Self {
super::cpu_local::inc_guard_count();