From 40274f5fac8e8169102b3033f39d3f053e0eb8cf Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 26 Feb 2022 13:46:11 -0800 Subject: [PATCH] [kernel] Fix logger::get_entry() blocking bug The new logger event object for making get_entry() block when no logs are available was consuming the event's notification even if the thread did not need to block. This was causing excessive blocking - if multiple logs had been added since the last call to get_entry(), only one would be returned, and the next call would block until yet another log was added. Now only call event::wait() to block the calling thread if there are no logs available. --- src/kernel/logger.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/kernel/logger.cpp b/src/kernel/logger.cpp index 9c6bc70..920bfc3 100644 --- a/src/kernel/logger.cpp +++ b/src/kernel/logger.cpp @@ -94,14 +94,18 @@ logger::output(level severity, logs area, const char *fmt, va_list args) size_t logger::get_entry(void *buffer, size_t size) { - m_event.wait(); util::scoped_lock lock {m_lock}; void *out; size_t out_size = m_buffer.get_block(&out); - if (out_size == 0 || out == 0) - return 0; + if (out_size == 0 || out == 0) { + m_event.wait(); + out_size = m_buffer.get_block(&out); + + if (out_size == 0 || out == 0) + return 0; + } kassert(out_size >= sizeof(entry), "Couldn't read a full entry"); if (out_size < sizeof(entry))