mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Remove the shim kernel crate
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
d76c7a5b1e
commit
dafd16075f
34
kernel/src/time/softirq.rs
Normal file
34
kernel/src/time/softirq.rs
Normal file
@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
|
||||
use ostd::{arch::timer, sync::RwLock, trap::SoftIrqLine};
|
||||
|
||||
use crate::softirq_id::TIMER_SOFTIRQ_ID;
|
||||
|
||||
static TIMER_SOFTIRQ_CALLBACKS: RwLock<Vec<Box<dyn Fn() + Sync + Send>>> = RwLock::new(Vec::new());
|
||||
|
||||
pub(super) fn init() {
|
||||
SoftIrqLine::get(TIMER_SOFTIRQ_ID).enable(timer_softirq_handler);
|
||||
|
||||
timer::register_callback(|| {
|
||||
SoftIrqLine::get(TIMER_SOFTIRQ_ID).raise();
|
||||
});
|
||||
}
|
||||
|
||||
/// Registers a function that will be executed during timer softirq.
|
||||
pub(super) fn register_callback<F>(func: F)
|
||||
where
|
||||
F: Fn() + Sync + Send + 'static,
|
||||
{
|
||||
TIMER_SOFTIRQ_CALLBACKS
|
||||
.write_irq_disabled()
|
||||
.push(Box::new(func));
|
||||
}
|
||||
|
||||
fn timer_softirq_handler() {
|
||||
let callbacks = TIMER_SOFTIRQ_CALLBACKS.read_irq_disabled();
|
||||
for callback in callbacks.iter() {
|
||||
(callback)();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user