| @@ -89,20 +89,24 @@ void ThreadedAnalyticsDestination::EventDispatcher::run() | |||||
| while (! threadShouldExit()) | while (! threadShouldExit()) | ||||
| { | { | ||||
| auto eventsToSendCapacity = maxBatchSize - eventsToSend.size(); | |||||
| if (eventsToSendCapacity > 0) | |||||
| { | { | ||||
| const ScopedLock lock (queueAccess); | |||||
| const auto numEventsInQueue = (int) eventQueue.size(); | |||||
| const auto numEventsInBatch = eventsToSend.size(); | |||||
| const auto freeBatchCapacity = maxBatchSize - numEventsInBatch; | |||||
| if (numEventsInQueue > 0) | |||||
| if (freeBatchCapacity > 0) | |||||
| { | { | ||||
| const auto numEventsToAdd = jmin (eventsToSendCapacity, numEventsInQueue); | |||||
| const auto numNewEvents = (int) eventQueue.size() - numEventsInBatch; | |||||
| if (numNewEvents > 0) | |||||
| { | |||||
| const ScopedLock lock (queueAccess); | |||||
| const auto numEventsToAdd = jmin (numNewEvents, freeBatchCapacity); | |||||
| const auto newBatchSize = numEventsInBatch + numEventsToAdd; | |||||
| for (size_t i = 0; i < (size_t) numEventsToAdd; ++i) | |||||
| eventsToSend.add (eventQueue[i]); | |||||
| for (size_t i = numEventsInBatch; i < (size_t) newBatchSize; ++i) | |||||
| eventsToSend.add (eventQueue[i]); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||