mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-17 00:44:19 +00:00
Fix a race condition in the plugin scanner
This commit is contained in:
parent
4c900be00a
commit
368ce48198
2 changed files with 47 additions and 17 deletions
|
|
@ -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))
|
||||
{
|
||||
// strange - found a duplicate plugin with different info..
|
||||
jassert (types.getUnchecked(i)->name == type.name);
|
||||
jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
|
||||
ScopedLock lock (typesArrayLock);
|
||||
|
||||
*types.getUnchecked(i) = type;
|
||||
return false;
|
||||
for (int i = types.size(); --i >= 0;)
|
||||
{
|
||||
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.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);
|
||||
|
||||
newOrder.addArray (types);
|
||||
oldOrder.addArray (types);
|
||||
|
||||
PluginSorter sorter (method, forwards);
|
||||
types.sort (sorter, true);
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue