forked from mirror/openmw-tes3mp
Using a mutex lock to prevent race conditions
This commit is contained in:
parent
e26c675829
commit
103a7ac628
1 changed files with 8 additions and 0 deletions
|
@ -339,8 +339,16 @@ void Launcher::DataFilesPage::slotAddonDataChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mutex lock to run reloadCells synchronously.
|
||||||
|
std::mutex _reloadCellsMutex;
|
||||||
|
|
||||||
void Launcher::DataFilesPage::reloadCells(QStringList selectedFiles)
|
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<std::mutex> lock(_reloadCellsMutex);
|
||||||
|
|
||||||
|
// The following code will run only if there is not another thread currently running it
|
||||||
CellNameLoader cellNameLoader;
|
CellNameLoader cellNameLoader;
|
||||||
QStringList cellNamesList = QStringList::fromSet(cellNameLoader.getCellNames(selectedFiles));
|
QStringList cellNamesList = QStringList::fromSet(cellNameLoader.getCellNames(selectedFiles));
|
||||||
std::sort(cellNamesList.begin(), cellNamesList.end());
|
std::sort(cellNamesList.begin(), cellNamesList.end());
|
||||||
|
|
Loading…
Reference in a new issue