mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 10:53:25 +00:00
Log messages to the serial atomically and rename arch::serial
Co-authored-by: Chuandong Li <lichuand@pku.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
6ff6db2167
commit
9e5f3123e1
@ -1,6 +1,14 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Logging support.
|
||||
//!
|
||||
//! Currently the logger prints the logs to the console.
|
||||
//!
|
||||
//! This module guarantees _atomicity_ under concurrency: messages are always
|
||||
//! printed in their entirety without being mixed with messages generated
|
||||
//! concurrently on other cores.
|
||||
//!
|
||||
//! IRQs are disabled while printing. So do not print long log messages.
|
||||
|
||||
use alloc::format;
|
||||
|
||||
@ -48,6 +56,11 @@ impl log::Log for Logger {
|
||||
(timestamp, level, record_str)
|
||||
};
|
||||
|
||||
// Use a global lock to prevent interleaving of log messages.
|
||||
use crate::sync::SpinLock;
|
||||
static RECORD_LOCK: SpinLock<()> = SpinLock::new(());
|
||||
let _lock = RECORD_LOCK.lock_irq_disabled();
|
||||
|
||||
early_println!("{} {}: {}", timestamp, level, record_str);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user