From 103a7ac62882d196b9fd12c9afa374f17a5e856f Mon Sep 17 00:00:00 2001 From: Thunderforge Date: Sun, 3 Jun 2018 16:32:12 -0500 Subject: [PATCH] Using a mutex lock to prevent race conditions --- apps/launcher/datafilespage.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index bcb2966d5..76ca893c4 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -339,8 +339,16 @@ void Launcher::DataFilesPage::slotAddonDataChanged() } } +// Mutex lock to run reloadCells synchronously. +std::mutex _reloadCellsMutex; + void Launcher::DataFilesPage::reloadCells(QStringList selectedFiles) { + // Use a mutex lock so that we can prevent two threads from executing the rest of this code at the same time + // Based on https://stackoverflow.com/a/5429695/531762 + std::unique_lock lock(_reloadCellsMutex); + + // The following code will run only if there is not another thread currently running it CellNameLoader cellNameLoader; QStringList cellNamesList = QStringList::fromSet(cellNameLoader.getCellNames(selectedFiles)); std::sort(cellNamesList.begin(), cellNamesList.end());