sel4_logging/
synchronized.rs
1use lock_api::{Mutex, RawMutex};
8use log::{Log, Metadata, Record};
9
10pub struct SynchronizedLogger<R, T>(Mutex<R, T>);
11
12impl<R: RawMutex, T> SynchronizedLogger<R, T> {
13 pub const fn new(inner: T) -> Self {
14 Self(Mutex::new(inner))
15 }
16}
17
18impl<R, T> SynchronizedLogger<R, T> {
19 pub const fn new_with_raw_mutex(raw_mutex: R, inner: T) -> Self {
20 Self(Mutex::from_raw(raw_mutex, inner))
21 }
22
23 pub fn into_inner(self) -> Mutex<R, T> {
24 self.0
25 }
26
27 pub fn inner(&self) -> &Mutex<R, T> {
28 &self.0
29 }
30
31 pub fn inner_mut(&mut self) -> &mut Mutex<R, T> {
32 &mut self.0
33 }
34}
35
36impl<R: RawMutex + Send + Sync, T: Log> Log for SynchronizedLogger<R, T> {
37 fn enabled(&self, metadata: &Metadata) -> bool {
38 self.inner().lock().enabled(metadata)
39 }
40
41 fn log(&self, record: &Record) {
42 self.inner().lock().log(record)
43 }
44
45 fn flush(&self) {
46 self.inner().lock().flush()
47 }
48}