From f8bff8dfdafb193c186b4e0a5305c7675f43eee0 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sat, 20 Oct 2018 01:59:09 +0200 Subject: [PATCH] data: Fixed deadlock when indexers started before commands in queue * Made refilling command queue faster to avoid indexers shutting down --- .../indexer/TaskFillIndexerCommandQueue.cpp | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp b/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp index 01ffded1..4d837450 100644 --- a/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp +++ b/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp @@ -64,6 +64,8 @@ void TaskFillIndexerCommandsQueue::doEnter(std::shared_ptr blackboar } } + fillCommandQueue(); + blackboard->set("indexer_command_queue_started", true); } @@ -73,7 +75,7 @@ Task::TaskState TaskFillIndexerCommandsQueue::doUpdate(std::shared_ptr lock(m_commandsMutex); - if (m_indexerCommandProvider->size() == 0) + if (m_indexerCommandProvider->empty()) { return STATE_SUCCESS; } @@ -110,23 +112,33 @@ void TaskFillIndexerCommandsQueue::handleMessage(MessageInterruptTasks* message) bool TaskFillIndexerCommandsQueue::fillCommandQueue() { - bool filled = false; - std::lock_guard lock(m_commandsMutex); + size_t refillAmount = m_maximumQueueSize - m_indexerCommandManager.indexerCommandCount(); + if (!refillAmount) + { + return false; + } - while (!m_indexerCommandProvider->empty() && m_indexerCommandManager.indexerCommandCount() < m_maximumQueueSize) + std::lock_guard lock(m_commandsMutex); + std::vector> commands; + + while (!m_indexerCommandProvider->empty() && commands.size() < refillAmount) { if (!m_filePathQueue.empty()) { - m_indexerCommandManager.pushIndexerCommands({ m_indexerCommandProvider->consumeCommandForSourceFilePath(m_filePathQueue.front()) }); + commands.push_back(m_indexerCommandProvider->consumeCommandForSourceFilePath(m_filePathQueue.front())); m_filePathQueue.pop(); } else { - m_indexerCommandManager.pushIndexerCommands({ m_indexerCommandProvider->consumeCommand() }); + commands.push_back(m_indexerCommandProvider->consumeCommand()); } - - filled = true; } - return filled; + if (commands.size()) + { + m_indexerCommandManager.pushIndexerCommands(commands); + return true; + } + + return false; }