mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 01:43:22 +00:00
Move the log lock to a better location
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
67e5e5a651
commit
d6e40933b8
@ -2,26 +2,6 @@
|
||||
|
||||
//! The console I/O.
|
||||
|
||||
use alloc::fmt;
|
||||
use core::fmt::Write;
|
||||
|
||||
/// Prints the formatted arguments to the standard output using the serial port.
|
||||
#[inline]
|
||||
pub fn print(args: fmt::Arguments) {
|
||||
Stdout.write_fmt(args).unwrap();
|
||||
}
|
||||
|
||||
struct Stdout;
|
||||
|
||||
impl Write for Stdout {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for &c in s.as_bytes() {
|
||||
send(c);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the serial port.
|
||||
pub(crate) fn init() {}
|
||||
|
||||
|
@ -2,29 +2,9 @@
|
||||
|
||||
//! The console I/O.
|
||||
|
||||
use alloc::fmt;
|
||||
use core::fmt::Write;
|
||||
|
||||
use super::device::serial::SerialPort;
|
||||
use crate::io::reserve_io_port_range;
|
||||
|
||||
/// Prints the formatted arguments to the standard output using the serial port.
|
||||
#[inline]
|
||||
pub fn print(args: fmt::Arguments) {
|
||||
Stdout.write_fmt(args).unwrap();
|
||||
}
|
||||
|
||||
struct Stdout;
|
||||
|
||||
impl Write for Stdout {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for &c in s.as_bytes() {
|
||||
send(c);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
struct LineSts: u8 {
|
||||
const INPUT_FULL = 1;
|
||||
|
@ -2,16 +2,34 @@
|
||||
|
||||
//! Console output.
|
||||
|
||||
use core::fmt::Arguments;
|
||||
use core::fmt::{self, Arguments, Write};
|
||||
|
||||
use crate::if_tdx_enabled;
|
||||
use crate::{
|
||||
if_tdx_enabled,
|
||||
sync::{LocalIrqDisabled, SpinLock},
|
||||
};
|
||||
|
||||
struct Stdout;
|
||||
|
||||
impl Write for Stdout {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for &c in s.as_bytes() {
|
||||
crate::arch::serial::send(c);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
static STDOUT: SpinLock<Stdout, LocalIrqDisabled> = SpinLock::new(Stdout);
|
||||
|
||||
/// Prints formatted arguments to the console.
|
||||
pub fn early_print(args: Arguments) {
|
||||
if_tdx_enabled!({
|
||||
// Hold the lock to prevent the logs from interleaving.
|
||||
let _guard = STDOUT.lock();
|
||||
tdx_guest::print(args);
|
||||
} else {
|
||||
crate::arch::serial::print(args);
|
||||
STDOUT.lock().write_fmt(args).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,7 @@ impl log::Log for Logger {
|
||||
};
|
||||
|
||||
// Default implementation.
|
||||
|
||||
let level = record.level();
|
||||
|
||||
// Use a global lock to prevent interleaving of log messages.
|
||||
use crate::sync::SpinLock;
|
||||
static RECORD_LOCK: SpinLock<()> = SpinLock::new(());
|
||||
let _lock = RECORD_LOCK.disable_irq().lock();
|
||||
|
||||
crate::console::early_print(format_args!("{}: {}\n", level, record.args()));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user