Skip to content

Commit 39249f2

Browse files
committed
refactor(interrupts): 优化APIC中断处理中的静态变量管理
1 parent cd57863 commit 39249f2

File tree

1 file changed

+4
-6
lines changed
  • kernel/src/interrupts/apic

1 file changed

+4
-6
lines changed

kernel/src/interrupts/apic/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::memory::protection;
55
use crate::{get_hhdm_offset, libs::acpi::ACPI_INFO};
66
use log::debug;
77
use raw_cpuid::CpuId;
8-
use spin::Mutex;
8+
use spin::Once;
99
use x86_64::registers::model_specific::Msr;
1010

1111
pub mod ioapic;
@@ -44,9 +44,7 @@ pub struct LocalApic {
4444
base: u64, // Virtual base address for xAPIC
4545
}
4646

47-
lazy_static::lazy_static! {
48-
pub static ref LAPIC: Mutex<Option<LocalApic>> = Mutex::new(None);
49-
}
47+
pub static LAPIC: Once<LocalApic> = Once::new();
5048

5149
impl LocalApic {
5250
pub unsafe fn new() -> Self {
@@ -152,7 +150,7 @@ impl LocalApic {
152150
}
153151

154152
pub fn end_of_interrupt() {
155-
if let Some(lapic) = LAPIC.lock().as_ref() {
153+
if let Some(lapic) = LAPIC.get() {
156154
unsafe { lapic.eoi() };
157155
}
158156
}
@@ -168,6 +166,6 @@ pub fn init() {
168166
let lapic = LocalApic::new();
169167
lapic.init();
170168
lapic.calibrate_timer();
171-
*LAPIC.lock() = Some(lapic);
169+
LAPIC.call_once(|| lapic);
172170
}
173171
}

0 commit comments

Comments
 (0)