@@ -51,26 +51,16 @@ void IcingaDB::PendingItemsThreadProc()
5151 // Wait until the initial config dump is done. IcingaDB::OnConnectedHandler will notify us once it's finished.
5252 while (GetActive () && !m_ConfigDumpDone) m_PendingItemsCV.wait (lock);
5353
54- // Predicate to determine whether the worker thread is allowed to process pending items.
55- auto canContinue = [this ] {
56- if (!GetActive ()) {
57- return true ;
58- }
59- return !m_PendingItems.empty () && m_RconWorker && m_RconWorker->IsConnected () && m_RconWorker->GetPendingQueryCount () < maxPendingQueries;
60- };
61-
62- while (true ) {
63- // Even if someone notifies us, we still need to verify whether the precondition is actually fulfilled.
64- // However, in case we don't receive any notification, we still want to wake up periodically on our own
65- // to check whether we can proceed (e.g. the Redis connection might have become available again and there
66- // was no activity on the pending items queue to trigger a notification). Thus, we use a timed wait here.
67- while (!canContinue ()) m_PendingItemsCV.wait_for (lock, 100ms);
68-
69- if (!GetActive ()) {
70- break ;
71- }
72- if (auto retryAfter = DequeueAndProcessOne (lock); retryAfter > 0ms) {
73- m_PendingItemsCV.wait_for (lock, retryAfter);
54+ while (GetActive ()) {
55+ if (!m_PendingItems.empty () && m_RconWorker && m_RconWorker->IsConnected () && m_RconWorker->GetPendingQueryCount () < maxPendingQueries) {
56+ if (auto retryAfter = DequeueAndProcessOne (lock); retryAfter > 0ms) {
57+ m_PendingItemsCV.wait_for (lock, retryAfter);
58+ }
59+ } else {
60+ // In case we don't receive any notification, we still want to wake up periodically on our own
61+ // to check whether we can proceed (e.g. the Redis connection might have become available again and there
62+ // was no activity on the pending items queue to trigger a notification). Thus, we use a timed wait here.
63+ m_PendingItemsCV.wait_for (lock, 100ms);
7464 }
7565 }
7666}
0 commit comments