Browse Source

Fix a race condition in the plugin scanner

tags/2021-05-28
hogliux 9 years ago
parent
commit
368ce48198
2 changed files with 46 additions and 16 deletions
  1. +45
    -15
      modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp
  2. +1
    -1
      modules/juce_audio_processors/scanning/juce_KnownPluginList.h

+ 45
- 15
modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp View File

@@ -27,6 +27,8 @@ KnownPluginList::~KnownPluginList() {}
void KnownPluginList::clear()
{
ScopedLock lock (typesArrayLock);
if (types.size() > 0)
{
types.clear();
@@ -36,6 +38,8 @@ void KnownPluginList::clear()
PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const
{
ScopedLock lock (typesArrayLock);
for (int i = 0; i < types.size(); ++i)
if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
return types.getUnchecked(i);
@@ -45,6 +49,8 @@ PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifi
PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const
{
ScopedLock lock (typesArrayLock);
for (int i = 0; i < types.size(); ++i)
if (types.getUnchecked(i)->matchesIdentifierString (identifierString))
return types.getUnchecked(i);
@@ -54,27 +60,37 @@ PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& id
bool KnownPluginList::addType (const PluginDescription& type)
{
for (int i = types.size(); --i >= 0;)
{
if (types.getUnchecked(i)->isDuplicateOf (type))
ScopedLock lock (typesArrayLock);
for (int i = types.size(); --i >= 0;)
{
// strange - found a duplicate plugin with different info..
jassert (types.getUnchecked(i)->name == type.name);
jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
if (types.getUnchecked(i)->isDuplicateOf (type))
{
// strange - found a duplicate plugin with different info..
jassert (types.getUnchecked(i)->name == type.name);
jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
*types.getUnchecked(i) = type;
return false;
*types.getUnchecked(i) = type;
return false;
}
}
types.insert (0, new PluginDescription (type));
}
types.insert (0, new PluginDescription (type));
sendChangeMessage();
return true;
}
void KnownPluginList::removeType (const int index)
{
types.remove (index);
{
ScopedLock lock (typesArrayLock);
types.remove (index);
}
sendChangeMessage();
}
@@ -84,6 +100,8 @@ bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier,
if (getTypeForFile (fileOrIdentifier) == nullptr)
return false;
ScopedLock lock (typesArrayLock);
for (int i = types.size(); --i >= 0;)
{
const PluginDescription* const d = types.getUnchecked(i);
@@ -113,6 +131,8 @@ bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
{
bool needsRescanning = false;
ScopedLock lock (typesArrayLock);
for (int i = types.size(); --i >= 0;)
{
const PluginDescription* const d = types.getUnchecked(i);
@@ -298,12 +318,17 @@ void KnownPluginList::sort (const SortMethod method, bool forwards)
if (method != defaultOrder)
{
Array<PluginDescription*> oldOrder, newOrder;
oldOrder.addArray (types);
PluginSorter sorter (method, forwards);
types.sort (sorter, true);
{
ScopedLock lock (typesArrayLock);
oldOrder.addArray (types);
PluginSorter sorter (method, forwards);
types.sort (sorter, true);
newOrder.addArray (types);
newOrder.addArray (types);
}
if (oldOrder != newOrder)
sendChangeMessage();
@@ -315,8 +340,12 @@ XmlElement* KnownPluginList::createXml() const
{
XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
for (int i = types.size(); --i >= 0;)
e->prependChildElement (types.getUnchecked(i)->createXml());
{
ScopedLock lock (typesArrayLock);
for (int i = types.size(); --i >= 0;)
e->prependChildElement (types.getUnchecked(i)->createXml());
}
for (int i = 0; i < blacklist.size(); ++i)
e->createNewChildElement ("BLACKLISTED")->setAttribute ("id", blacklist[i]);
@@ -516,6 +545,7 @@ KnownPluginList::PluginTree* KnownPluginList::createTree (const SortMethod sortM
Array<PluginDescription*> sorted;
{
ScopedLock lock (typesArrayLock);
PluginSorter sorter (sortMethod, true);
for (int i = 0; i < types.size(); ++i)


+ 1
- 1
modules/juce_audio_processors/scanning/juce_KnownPluginList.h View File

@@ -216,7 +216,7 @@ private:
OwnedArray<PluginDescription> types;
StringArray blacklist;
ScopedPointer<CustomScanner> scanner;
CriticalSection scanLock;
CriticalSection scanLock, typesArrayLock;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KnownPluginList)
};


Loading…
Cancel
Save