Resolve review comments.

This commit is contained in:
Guillaume Endignoux
2020-03-18 15:28:37 +01:00
parent c7493d1b9d
commit a7c79c4f23

View File

@@ -1,8 +1,8 @@
diff --git a/src/console.rs b/src/console.rs diff --git a/src/console.rs b/src/console.rs
index ecd7ad1..785de01 100644 index ecd7ad1..ae1b826 100644
--- a/src/console.rs --- a/src/console.rs
+++ b/src/console.rs +++ b/src/console.rs
@@ -16,33 +16,58 @@ mod allow_nr { @@ -16,33 +16,63 @@ mod allow_nr {
pub const SHARE_BUFFER: usize = 1; pub const SHARE_BUFFER: usize = 1;
} }
@@ -55,7 +55,12 @@ index ecd7ad1..785de01 100644
} }
- fn flush(&mut self, num_bytes_to_print: usize) { - fn flush(&mut self, num_bytes_to_print: usize) {
+ fn flush(&mut self) { + pub fn flush(&mut self) {
+ if self.is_empty() {
+ // Don't trigger any syscall if the buffer is empty.
+ return;
+ }
+
+ let count = self.count_pending; + let count = self.count_pending;
+ // Clear the buffer even in case of error, to avoid an infinite loop. + // Clear the buffer even in case of error, to avoid an infinite loop.
+ self.count_pending = 0; + self.count_pending = 0;
@@ -68,7 +73,7 @@ index ecd7ad1..785de01 100644
); );
if result.is_err() { if result.is_err() {
return; return;
@@ -59,8 +84,7 @@ impl Console { @@ -59,8 +89,7 @@ impl Console {
return; return;
} }
@@ -78,15 +83,13 @@ index ecd7ad1..785de01 100644
if result_code < 0 { if result_code < 0 {
return; return;
} }
@@ -69,6 +93,14 @@ impl Console { @@ -69,6 +98,12 @@ impl Console {
} }
} }
+impl Drop for Console { +impl Drop for Console {
+ fn drop(&mut self) { + fn drop(&mut self) {
+ if !self.is_empty() { + self.flush();
+ self.flush();
+ }
+ } + }
+} +}
+ +