Refactor the this_cpu API with PinCurrentCpu

This commit is contained in:
Zhang Junyang
2024-08-19 20:32:14 +08:00
committed by Tate, Hongliang Tian
parent 9a94ba23aa
commit f7a9510be0
17 changed files with 123 additions and 75 deletions

View File

@ -4,7 +4,7 @@
//! on a CPU with a single 32-bit, CPU-local integer value.
//!
//! * Bits from 0 to 30 represents an unsigned counter called `guard_count`,
//! which is the number of `DisablePreemptGuard` instances held by the
//! which is the number of `DisabledPreemptGuard` instances held by the
//! current CPU;
//! * Bit 31 is set to `!need_preempt`, where `need_preempt` is a boolean value
//! that will be set by the scheduler when it decides that the current task

View File

@ -3,14 +3,14 @@
/// A guard for disable preempt.
#[clippy::has_significant_drop]
#[must_use]
pub struct DisablePreemptGuard {
pub struct DisabledPreemptGuard {
// This private field prevents user from constructing values of this type directly.
_private: (),
}
impl !Send for DisablePreemptGuard {}
impl !Send for DisabledPreemptGuard {}
impl DisablePreemptGuard {
impl DisabledPreemptGuard {
fn new() -> Self {
super::cpu_local::inc_guard_count();
Self { _private: () }
@ -23,13 +23,13 @@ impl DisablePreemptGuard {
}
}
impl Drop for DisablePreemptGuard {
impl Drop for DisabledPreemptGuard {
fn drop(&mut self) {
super::cpu_local::dec_guard_count();
}
}
/// Disables preemption.
pub fn disable_preempt() -> DisablePreemptGuard {
DisablePreemptGuard::new()
pub fn disable_preempt() -> DisabledPreemptGuard {
DisabledPreemptGuard::new()
}

View File

@ -3,4 +3,4 @@
pub(super) mod cpu_local;
mod guard;
pub use self::guard::{disable_preempt, DisablePreemptGuard};
pub use self::guard::{disable_preempt, DisabledPreemptGuard};