rewrite to remove Cpu::current_raw()
This commit is contained in:
parent
ec9c0cbe4d
commit
73e3ab9ebc
@ -34,12 +34,7 @@ impl Cpu {
|
||||
/// Return this CPU's cpu struct.
|
||||
/// Interrupts must be disabled.
|
||||
pub fn current() -> &'static mut Cpu {
|
||||
unsafe { &mut *Cpu::current_raw() }
|
||||
}
|
||||
/// Return this CPU's cpu struct.
|
||||
/// Interrupts must be disabled.
|
||||
pub unsafe fn current_raw() -> *mut Cpu {
|
||||
addr_of_mut!(CPUS[Cpu::current_id()])
|
||||
unsafe { &mut CPUS[Cpu::current_id()] }
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,5 +42,5 @@ impl Cpu {
|
||||
/// Interrupts must be disabled.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn mycpu() -> *mut Cpu {
|
||||
Cpu::current_raw()
|
||||
addr_of_mut!(*Cpu::current())
|
||||
}
|
||||
|
@ -101,8 +101,7 @@ pub struct Proc {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn myproc() -> *mut Proc {
|
||||
let _ = crate::trap::InterruptBlocker::new();
|
||||
let c = Cpu::current_raw();
|
||||
(*c).proc
|
||||
Cpu::current().proc
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -183,9 +182,9 @@ pub unsafe fn r#yield() {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sched() {
|
||||
let p = myproc();
|
||||
let c = Cpu::current_raw();
|
||||
let cpu = Cpu::current();
|
||||
|
||||
if (*c).interrupt_disable_layers != 1 {
|
||||
if cpu.interrupt_disable_layers != 1 {
|
||||
panic!("sched locks");
|
||||
} else if (*p).state == ProcState::Running {
|
||||
panic!("sched running");
|
||||
@ -193,9 +192,9 @@ pub unsafe extern "C" fn sched() {
|
||||
panic!("sched interruptible");
|
||||
}
|
||||
|
||||
let previous_interrupts_enabled = (*c).previous_interrupts_enabled;
|
||||
swtch(addr_of_mut!((*p).context), addr_of_mut!((*c).context));
|
||||
(*c).previous_interrupts_enabled = previous_interrupts_enabled;
|
||||
let previous_interrupts_enabled = cpu.previous_interrupts_enabled;
|
||||
swtch(addr_of_mut!((*p).context), addr_of_mut!(cpu.context));
|
||||
cpu.previous_interrupts_enabled = previous_interrupts_enabled;
|
||||
}
|
||||
|
||||
/// The lock should already be locked.
|
||||
|
@ -90,14 +90,14 @@ impl InterruptBlocker {
|
||||
pub fn new() -> InterruptBlocker {
|
||||
unsafe {
|
||||
let interrupts_before = intr_get();
|
||||
let cpu = Cpu::current_raw();
|
||||
let cpu = Cpu::current();
|
||||
|
||||
intr_off();
|
||||
|
||||
if (*cpu).interrupt_disable_layers == 0 {
|
||||
(*cpu).previous_interrupts_enabled = interrupts_before;
|
||||
if cpu.interrupt_disable_layers == 0 {
|
||||
cpu.previous_interrupts_enabled = interrupts_before;
|
||||
}
|
||||
(*cpu).interrupt_disable_layers += 1;
|
||||
cpu.interrupt_disable_layers += 1;
|
||||
// crate::sync::spinlock::push_off();
|
||||
}
|
||||
InterruptBlocker
|
||||
@ -106,16 +106,16 @@ impl InterruptBlocker {
|
||||
impl core::ops::Drop for InterruptBlocker {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let cpu = Cpu::current_raw();
|
||||
let cpu = Cpu::current();
|
||||
|
||||
if intr_get() == 1 || (*cpu).interrupt_disable_layers < 1 {
|
||||
if intr_get() == 1 || cpu.interrupt_disable_layers < 1 {
|
||||
// panic!("pop_off mismatched");
|
||||
return;
|
||||
}
|
||||
|
||||
(*cpu).interrupt_disable_layers -= 1;
|
||||
cpu.interrupt_disable_layers -= 1;
|
||||
|
||||
if (*cpu).interrupt_disable_layers == 0 && (*cpu).previous_interrupts_enabled == 1 {
|
||||
if cpu.interrupt_disable_layers == 0 && cpu.previous_interrupts_enabled == 1 {
|
||||
intr_on();
|
||||
}
|
||||
// crate::sync::spinlock::pop_off();
|
||||
@ -272,28 +272,28 @@ pub unsafe extern "C" fn usertrap() {
|
||||
|
||||
pub unsafe fn push_intr_off() {
|
||||
let old = intr_get();
|
||||
let cpu = Cpu::current_raw();
|
||||
let cpu = Cpu::current();
|
||||
|
||||
intr_off();
|
||||
if (*cpu).interrupt_disable_layers == 0 {
|
||||
(*cpu).previous_interrupts_enabled = old;
|
||||
if cpu.interrupt_disable_layers == 0 {
|
||||
cpu.previous_interrupts_enabled = old;
|
||||
}
|
||||
(*cpu).interrupt_disable_layers += 1;
|
||||
cpu.interrupt_disable_layers += 1;
|
||||
}
|
||||
pub unsafe fn pop_intr_off() {
|
||||
let cpu = Cpu::current_raw();
|
||||
let cpu = Cpu::current();
|
||||
|
||||
if intr_get() == 1 {
|
||||
// crate::panic_byte(b'0');
|
||||
panic!("pop_intr_off - interruptible");
|
||||
} else if (*cpu).interrupt_disable_layers < 1 {
|
||||
} else if cpu.interrupt_disable_layers < 1 {
|
||||
// crate::panic_byte(b'1');
|
||||
panic!("pop_intr_off");
|
||||
}
|
||||
|
||||
(*cpu).interrupt_disable_layers -= 1;
|
||||
cpu.interrupt_disable_layers -= 1;
|
||||
|
||||
if (*cpu).interrupt_disable_layers == 0 && (*cpu).previous_interrupts_enabled == 1 {
|
||||
if cpu.interrupt_disable_layers == 0 && cpu.previous_interrupts_enabled == 1 {
|
||||
intr_on();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user