mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 21:36:48 +00:00
Make VirtioConsolesPrinter heapless
This commit is contained in:
parent
d37e60d082
commit
96d83e43b4
@ -13,7 +13,7 @@ use core::any::Any;
|
|||||||
use component::{init_component, ComponentInitError};
|
use component::{init_component, ComponentInitError};
|
||||||
use ostd::{
|
use ostd::{
|
||||||
mm::{Infallible, VmReader},
|
mm::{Infallible, VmReader},
|
||||||
sync::SpinLock,
|
sync::{LocalIrqDisabled, SpinLock, SpinLockGuard},
|
||||||
};
|
};
|
||||||
use spin::Once;
|
use spin::Once;
|
||||||
|
|
||||||
@ -52,6 +52,16 @@ pub fn all_devices() -> Vec<(String, Arc<dyn AnyConsoleDevice>)> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn all_devices_lock<'a>(
|
||||||
|
) -> SpinLockGuard<'a, BTreeMap<String, Arc<dyn AnyConsoleDevice>>, LocalIrqDisabled> {
|
||||||
|
COMPONENT
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.console_device_table
|
||||||
|
.disable_irq()
|
||||||
|
.lock()
|
||||||
|
}
|
||||||
|
|
||||||
static COMPONENT: Once<Component> = Once::new();
|
static COMPONENT: Once<Component> = Once::new();
|
||||||
|
|
||||||
#[init_component]
|
#[init_component]
|
||||||
|
@ -11,7 +11,11 @@ struct VirtioConsolesPrinter;
|
|||||||
|
|
||||||
impl Write for VirtioConsolesPrinter {
|
impl Write for VirtioConsolesPrinter {
|
||||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||||
for (_, device) in aster_console::all_devices() {
|
// We must call `all_devices_lock` instead of `all_devices` here, as `all_devices` invokes
|
||||||
|
// the clone method of String and Arc, which may lead to a deadlock when there is low memory
|
||||||
|
// in the heap (The heap allocator will log a message when memory is low.).
|
||||||
|
let devices = aster_console::all_devices_lock();
|
||||||
|
for (_, device) in devices.iter() {
|
||||||
device.send(s.as_bytes());
|
device.send(s.as_bytes());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user