1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-08 04:20:09 +00:00

DirectoryContentsList: Fix a data race

Fix improper use of non-atomic pointer validity to report state of background search thread state
This commit is contained in:
Oli 2022-03-22 11:52:15 +00:00
parent ed4f638ff7
commit 15bdae16b2
2 changed files with 7 additions and 5 deletions

View file

@ -66,10 +66,10 @@ void DirectoryContentsList::setDirectory (const File& directory,
auto newFlags = fileTypeFlags;
if (includeDirectories) newFlags |= File::findDirectories;
if (includeDirectories) newFlags |= File::findDirectories;
else newFlags &= ~File::findDirectories;
if (includeFiles) newFlags |= File::findFiles;
if (includeFiles) newFlags |= File::findFiles;
else newFlags &= ~File::findFiles;
setTypeFlags (newFlags);
@ -88,7 +88,7 @@ void DirectoryContentsList::stopSearching()
{
shouldStop = true;
thread.removeTimeSliceClient (this);
fileFindHandle = nullptr;
isSearching = false;
}
void DirectoryContentsList::clear()
@ -110,8 +110,9 @@ void DirectoryContentsList::refresh()
if (root.isDirectory())
{
fileFindHandle = std::make_unique<RangedDirectoryIterator> (root, false, "*", fileTypeFlags);
fileFindHandle = std::make_unique<RangedDirectoryIterator>(root, false, "*", fileTypeFlags);
shouldStop = false;
isSearching = true;
thread.addTimeSliceClient (this);
}
}
@ -165,7 +166,7 @@ bool DirectoryContentsList::contains (const File& targetFile) const
bool DirectoryContentsList::isStillLoading() const
{
return fileFindHandle != nullptr;
return isSearching;
}
void DirectoryContentsList::changed()

View file

@ -209,6 +209,7 @@ private:
std::unique_ptr<RangedDirectoryIterator> fileFindHandle;
std::atomic<bool> shouldStop { true };
bool isSearching = false;
bool wasEmpty = true;