summaryrefslogtreecommitdiff
path: root/src/organizercore.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-02-14 01:53:59 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-02-18 17:25:03 -0500
commit567fe019ac21ee78a07beae1a387ab5688e7f97b (patch)
tree6387ae5cff0f3a86627fbbb1f0b3344f913e7205 /src/organizercore.cpp
parentc8fc7abade6e28507f2a1590007a098e647026a9 (diff)
removed some unnecessary counters
delete old structure in thread
Diffstat (limited to 'src/organizercore.cpp')
-rw-r--r--src/organizercore.cpp68
1 files changed, 50 insertions, 18 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 86abeb35..a3202153 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -144,6 +144,10 @@ OrganizerCore::~OrganizerCore()
m_RefresherThread.exit();
m_RefresherThread.wait();
+ if (m_StructureDeleter.joinable()) {
+ m_StructureDeleter.join();
+ }
+
saveCurrentProfile();
// profile has to be cleaned up before the modinfo-buffer is cleared
@@ -1379,46 +1383,74 @@ std::vector<QString> OrganizerCore::enabledArchives()
void OrganizerCore::refreshDirectoryStructure()
{
- if (!m_DirectoryUpdate) {
- m_CurrentProfile->writeModlistNow(true);
+ if (m_DirectoryUpdate) {
+ log::debug("can't refresh, already in progress");
+ return;
+ }
- m_DirectoryUpdate = true;
- std::vector<std::tuple<QString, QString, int>> activeModList
- = m_CurrentProfile->getActiveMods();
- auto archives = enabledArchives();
- m_DirectoryRefresher.setMods(
- activeModList, std::set<QString>(archives.begin(), archives.end()));
+ log::debug("refreshing structure");
+ m_DirectoryUpdate = true;
- QTimer::singleShot(0, &m_DirectoryRefresher, SLOT(refresh()));
- }
+ m_CurrentProfile->writeModlistNow(true);
+ const auto activeModList = m_CurrentProfile->getActiveMods();
+ const auto archives = enabledArchives();
+
+ m_DirectoryRefresher.setMods(
+ activeModList, std::set<QString>(archives.begin(), archives.end()));
+
+ // runs refresh() in a thread
+ QTimer::singleShot(0, &m_DirectoryRefresher, SLOT(refresh()));
}
void OrganizerCore::directory_refreshed()
{
- DirectoryEntry *newStructure = m_DirectoryRefresher.getDirectoryStructure();
+ log::debug("structure refreshed");
+
+ DirectoryEntry *newStructure = m_DirectoryRefresher.stealDirectoryStructure();
Q_ASSERT(newStructure != m_DirectoryStructure);
- if (newStructure != nullptr) {
- std::swap(m_DirectoryStructure, newStructure);
- delete newStructure;
- } else {
+
+ if (newStructure == nullptr) {
// TODO: don't know why this happens, this slot seems to get called twice
// with only one emit
return;
}
+
+ std::swap(m_DirectoryStructure, newStructure);
+
+ if (m_StructureDeleter.joinable()) {
+ m_StructureDeleter.join();
+ }
+
+ m_StructureDeleter = std::thread([=]{
+ log::debug("structure deleter thread start");
+ delete newStructure;
+ log::debug("structure deleter thread done");
+ });
+
m_DirectoryUpdate = false;
+ log::debug("clearing caches");
for (int i = 0; i < m_ModList.rowCount(); ++i) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(i);
modInfo->clearCaches();
}
- for (auto task : m_PostRefreshTasks) {
- task();
+
+ if (!m_PostRefreshTasks.empty()) {
+ log::debug("running {} post refresh tasks", m_PostRefreshTasks.size());
+
+ for (auto task : m_PostRefreshTasks) {
+ task();
+ }
+
+ m_PostRefreshTasks.clear();
}
- m_PostRefreshTasks.clear();
if (m_CurrentProfile != nullptr) {
+ log::debug("refreshing lists");
refreshLists();
}
+
+ log::debug("refresh done");
}
void OrganizerCore::profileRefresh()