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:
parent
ed4f638ff7
commit
15bdae16b2
2 changed files with 7 additions and 5 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ private:
|
|||
|
||||
std::unique_ptr<RangedDirectoryIterator> fileFindHandle;
|
||||
std::atomic<bool> shouldStop { true };
|
||||
bool isSearching = false;
|
||||
|
||||
bool wasEmpty = true;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue