mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 14:23:55 +00:00
Refactor the this_cpu
API with PinCurrentCpu
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
9a94ba23aa
commit
f7a9510be0
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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};
|
||||
|
Reference in New Issue
Block a user