فهرست منبع

Move the line lock to the `write` model.

Assertions previously cluttered too, this fixes it by doing the same (i.e. locking a line lock) in the assertion macros.
ticki 8 سال پیش
والد
کامیت
c139b44ef8
2فایلهای تغییر یافته به همراه11 افزوده شده و 6 حذف شده
  1. 1 6
      src/log.rs
  2. 10 0
      src/write.rs

+ 1 - 6
src/log.rs

@@ -25,7 +25,7 @@ macro_rules! log {
             use log::internal::IntoCursor;
 
             // To avoid cluttering the lines, we acquire a lock.
-            let _lock = log::internal::LINE_LOCK.lock();
+            let _lock = write::LINE_LOCK.lock();
 
             // Print the pool state.
             let mut stderr = write::Writer::stderr();
@@ -52,11 +52,6 @@ pub mod internal {
     use core::cell::Cell;
     use core::ops::Range;
 
-    /// The line lock.
-    ///
-    /// This lock is used to avoid bungling and intertwining lines.
-    pub static LINE_LOCK: Mutex<()> = Mutex::new(());
-
     /// A "cursor".
     ///
     /// Cursors represents a block or an interval in the log output. This trait is implemented for

+ 10 - 0
src/write.rs

@@ -3,6 +3,8 @@
 //! This will replace the assertion macros to avoid deadlocks in panics, by utilizing a
 //! non-allocating writing primitive.
 
+use prelude::*;
+
 use core::fmt;
 
 extern {
@@ -10,6 +12,11 @@ extern {
     fn write(fd: i32, buff: *const u8, size: usize) -> isize;
 }
 
+/// The line lock.
+///
+/// This lock is used to avoid bungling and intertwining lines.
+pub static LINE_LOCK: Mutex<()> = Mutex::new(());
+
 /// A direct writer.
 ///
 /// This writes directly to some file descriptor through the `write` symbol.
@@ -51,6 +58,9 @@ macro_rules! assert {
         use core::fmt::Write;
 
         if !$e {
+            // To avoid cluttering the lines, we acquire a lock.
+            let _lock = write::LINE_LOCK.lock();
+
             let _ = write!(write::Writer::stderr(), "assertion failed at {}:{}: `{}` - ", file!(),
                            line!(), stringify!($e));
             let _ = writeln!(write::Writer::stderr(), $( $arg ),*);