mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[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.
This commit is contained in:
@@ -94,14 +94,18 @@ logger::output(level severity, logs area, const char *fmt, va_list args)
|
|||||||
size_t
|
size_t
|
||||||
logger::get_entry(void *buffer, size_t size)
|
logger::get_entry(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
m_event.wait();
|
|
||||||
|
|
||||||
util::scoped_lock lock {m_lock};
|
util::scoped_lock lock {m_lock};
|
||||||
|
|
||||||
void *out;
|
void *out;
|
||||||
size_t out_size = m_buffer.get_block(&out);
|
size_t out_size = m_buffer.get_block(&out);
|
||||||
if (out_size == 0 || out == 0)
|
if (out_size == 0 || out == 0) {
|
||||||
return 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");
|
kassert(out_size >= sizeof(entry), "Couldn't read a full entry");
|
||||||
if (out_size < sizeof(entry))
|
if (out_size < sizeof(entry))
|
||||||
|
|||||||
Reference in New Issue
Block a user