veridian_kernel/
print_capture.rs1use alloc::string::String;
8use core::{
9 fmt,
10 sync::atomic::{AtomicBool, Ordering},
11};
12
13use spin::Mutex;
14
15static CAPTURING: AtomicBool = AtomicBool::new(false);
17
18static CAPTURE_BUF: Mutex<Option<String>> = Mutex::new(None);
20
21pub fn start_capture() {
23 let mut buf = CAPTURE_BUF.lock();
24 *buf = Some(String::new());
25 CAPTURING.store(true, Ordering::Release);
26}
27
28pub fn stop_capture() -> String {
30 CAPTURING.store(false, Ordering::Release);
31 let mut buf = CAPTURE_BUF.lock();
32 buf.take().unwrap_or_default()
33}
34
35pub fn _capture_print(args: fmt::Arguments) {
37 if CAPTURING.load(Ordering::Acquire) {
38 use core::fmt::Write;
39 let mut buf = CAPTURE_BUF.lock();
40 if let Some(ref mut s) = *buf {
41 let _ = s.write_fmt(args);
42 }
43 }
44}