Skip to content

Commit

Permalink
Help the scheduler when there are more threads than physical cores
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Oct 17, 2024
1 parent 5ee2ba2 commit 4999aef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/cpp/asyncappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,13 @@ void AsyncAppender::append(const spi::LoggingEventPtr& event, Pool& p)
// Write to the ring buffer
priv->buffer[index] = AsyncAppenderPriv::EventData{event, pendingCount};
// Notify the dispatch thread that an event has been added
auto failureCount = 0;
auto savedEventCount = oldEventCount;
while (!priv->commitCount.compare_exchange_weak(oldEventCount, oldEventCount + 1, std::memory_order_acq_rel))
while (!priv->commitCount.compare_exchange_weak(oldEventCount, oldEventCount + 1, std::memory_order_release))
{
oldEventCount = savedEventCount;
oldEventCount = savedEventCount;
if (2 < ++failureCount) // Did the scheduler suspend a thread between claiming a slot and advancing commitCount?
std::this_thread::yield(); // Wait a bit
}
priv->bufferNotEmpty.notify_all();
break;
Expand Down

0 comments on commit 4999aef

Please sign in to comment.