From ef811009580260ae71e1fca462cea8c1f06876d2 Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Thu, 22 May 2025 20:55:57 +0800 Subject: [PATCH] Add `InAtomicMode: Debug` --- ostd/src/task/atomic_mode.rs | 12 ++++++------ ostd/src/trap/irq.rs | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ostd/src/task/atomic_mode.rs b/ostd/src/task/atomic_mode.rs index 9d1461b3..f20f2feb 100644 --- a/ostd/src/task/atomic_mode.rs +++ b/ostd/src/task/atomic_mode.rs @@ -50,17 +50,17 @@ pub fn might_sleep() { /// /// Key kernel primitives such as `SpinLock` and `Rcu` rely on /// [the atomic mode](crate::task::atomic_mode) for correctness or soundness. -/// The existence of such a guard guarantees that -/// the current task is executing in the atomic mode. +/// The existence of such a guard guarantees that the current task is executing +/// in the atomic mode. +/// +/// It requires [`core::fmt::Debug`] by default to make it easier to derive +/// [`Debug`] for types with `&dyn InAtomicMode`. /// /// # Safety /// /// The implementer must ensure that the atomic mode is maintained while /// the guard type is alive. -/// -/// [`DisabledLocalIrqGuard`]: crate::task::DisabledPreemptGuard -/// [`DisabledPreemptGuard`]: crate::trap::DisabledLocalIrqGuard -pub unsafe trait InAtomicMode {} +pub unsafe trait InAtomicMode: core::fmt::Debug {} /// Abstracts any type from which one can obtain a reference to an atomic-mode guard. pub trait AsAtomicModeGuard { diff --git a/ostd/src/trap/irq.rs b/ostd/src/trap/irq.rs index 74c7587f..ee2290bf 100644 --- a/ostd/src/trap/irq.rs +++ b/ostd/src/trap/irq.rs @@ -139,6 +139,7 @@ pub fn disable_local() -> DisabledLocalIrqGuard { /// A guard for disabled local IRQs. #[clippy::has_significant_drop] #[must_use] +#[derive(Debug)] pub struct DisabledLocalIrqGuard { was_enabled: bool, }