@@ -223,6 +223,11 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
223
223
std::lock_guard<std::mutex> lock (this ->bufferMutex );
224
224
this ->closed = true ;
225
225
}
226
+
227
+ /* *
228
+ * Used to ensure the dispatch thread does not wait when a logging thread is waiting.
229
+ */
230
+ int blockedCount{0 };
226
231
};
227
232
228
233
@@ -313,11 +318,11 @@ void AsyncAppender::append(const spi::LoggingEventPtr& event, Pool& p)
313
318
priv->bufferNotEmpty .notify_all ();
314
319
break ;
315
320
}
316
- priv->bufferNotEmpty .notify_all ();
317
321
//
318
322
// Following code is only reachable if buffer is full or eventCount has overflowed
319
323
//
320
324
std::unique_lock<std::mutex> lock (priv->bufferMutex );
325
+ priv->bufferNotEmpty .notify_all ();
321
326
//
322
327
// if blocking and thread is not already interrupted
323
328
// and not the dispatcher then
@@ -328,10 +333,12 @@ void AsyncAppender::append(const spi::LoggingEventPtr& event, Pool& p)
328
333
&& !priv->closed
329
334
&& (priv->dispatcher .get_id () != std::this_thread::get_id ()) )
330
335
{
336
+ ++priv->blockedCount ;
331
337
priv->bufferNotFull .wait (lock, [this ]()
332
338
{
333
339
return priv->eventCount - priv->dispatchedCount < priv->bufferSize ;
334
340
});
341
+ --priv->blockedCount ;
335
342
discard = false ;
336
343
}
337
344
@@ -519,7 +526,7 @@ void AsyncAppender::dispatch()
519
526
{
520
527
std::unique_lock<std::mutex> lock (priv->bufferMutex );
521
528
priv->bufferNotEmpty .wait (lock, [this ]() -> bool
522
- { return priv->dispatchedCount != priv->commitCount || priv->closed ; }
529
+ { return 0 < priv-> blockedCount || priv->dispatchedCount != priv->commitCount || priv->closed ; }
523
530
);
524
531
}
525
532
isActive = !priv->isClosed ();
0 commit comments