Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the buffer's mutex for asynchronous flushes
  • Loading branch information
koute committed Oct 21, 2021
commit ce69d8c973dc0e188330d3e24e532dd82bfed397
8 changes: 3 additions & 5 deletions client/tracing/src/logging/stderr_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ static BUFFER: Mutex<Vec<u8>> = parking_lot::const_mutex(Vec::new());
/// A spare buffer which we'll swap with the main buffer on each flush to minimize lock contention.
static SPARE_BUFFER: Mutex<Vec<u8>> = parking_lot::const_mutex(Vec::new());

/// A mutex used only as a cheap channel to trigger asynchronous flushes.
static ASYNC_FLUSH_MUTEX: Mutex<()> = parking_lot::const_mutex(());
/// A conditional variable used to forcefully trigger asynchronous flushes.
static ASYNC_FLUSH_CONDVAR: Condvar = Condvar::new();

static ENABLE_ASYNC_LOGGING: AtomicBool = AtomicBool::new(true);
Expand All @@ -97,10 +96,9 @@ fn flush_logs(mut buffer: parking_lot::lock_api::MutexGuard<parking_lot::RawMute
}

fn log_autoflush_thread() {
let mut lock = ASYNC_FLUSH_MUTEX.lock();
let mut buffer = BUFFER.lock();
loop {
ASYNC_FLUSH_CONDVAR.wait_for(&mut lock, AUTOFLUSH_EVERY);
let mut buffer = BUFFER.lock();
ASYNC_FLUSH_CONDVAR.wait_for(&mut buffer, AUTOFLUSH_EVERY);
loop {
flush_logs(buffer);

Expand Down