diff --git a/extras/AudioPluginHost/Source/HostStartup.cpp b/extras/AudioPluginHost/Source/HostStartup.cpp index b3c5e4ba78..4eae83647d 100644 --- a/extras/AudioPluginHost/Source/HostStartup.cpp +++ b/extras/AudioPluginHost/Source/HostStartup.cpp @@ -48,13 +48,15 @@ private: if (mb.isEmpty()) return; - if (! doScan (mb)) - { - { - const std::lock_guard lock (mutex); - pendingBlocks.emplace (mb); - } + const std::lock_guard lock (mutex); + if (const auto results = doScan (mb); ! results.isEmpty()) + { + sendResults (results); + } + else + { + pendingBlocks.emplace (mb); triggerAsyncUpdate(); } } @@ -68,26 +70,17 @@ private: { for (;;) { - const auto block = [&]() -> MemoryBlock - { - const std::lock_guard lock (mutex); + const std::lock_guard lock (mutex); - if (pendingBlocks.empty()) - return {}; - - auto out = std::move (pendingBlocks.front()); - pendingBlocks.pop(); - return out; - }(); - - if (block.isEmpty()) + if (pendingBlocks.empty()) return; - doScan (block); + sendResults (doScan (pendingBlocks.front())); + pendingBlocks.pop(); } } - bool doScan (const MemoryBlock& block) + OwnedArray doScan (const MemoryBlock& block) { MemoryInputStream stream { block, false }; const auto formatName = stream.readString(); @@ -106,20 +99,19 @@ private: return nullptr; }(); - if (matchingFormat == nullptr - || (! MessageManager::getInstance()->isThisTheMessageThread() - && ! matchingFormat->requiresUnblockedMessageThreadDuringCreation (pd))) + OwnedArray results; + + if (matchingFormat != nullptr + && (MessageManager::getInstance()->isThisTheMessageThread() + || matchingFormat->requiresUnblockedMessageThreadDuringCreation (pd))) { - return false; + matchingFormat->findAllTypesForFile (results, identifier); } - OwnedArray results; - matchingFormat->findAllTypesForFile (results, identifier); - sendPluginDescriptions (results); - return true; + return results; } - void sendPluginDescriptions (const OwnedArray& results) + void sendResults (const OwnedArray& results) { XmlElement xml ("LIST"); @@ -132,9 +124,6 @@ private: std::mutex mutex; std::queue pendingBlocks; - - // After construction, this will only be accessed by doScan so there's no need - // to worry about synchronisation. AudioPluginFormatManager formatManager; };