summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-05-24 13:28:00 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2020-05-24 13:28:00 +0200
commita284c64dc109797514b4664d37e6b6dc3d5c36c7 (patch)
tree4bdcc262f253912576b932aecc8eccb2ab72f17c /src
parent9fb639a00e1a809a9ea9b5e68777ec46f534761c (diff)
Update file tree in parallel when loading from disk.
Diffstat (limited to 'src')
-rw-r--r--src/modinfo.cpp8
-rw-r--r--src/modinfo.h31
2 files changed, 39 insertions, 0 deletions
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index 0dd113c5..5a90d74b 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -29,6 +29,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "modinfodialog.h"
#include "overwriteinfodialog.h"
#include "versioninfo.h"
+#include "envfs.h"
#include <iplugingame.h>
#include <versioninfo.h>
@@ -45,6 +46,7 @@ using namespace MOBase;
using namespace MOShared;
+env::ThreadPool<ModInfo::ModThread> ModInfo::s_Threads(10);
std::vector<ModInfo::Ptr> ModInfo::s_Collection;
std::map<QString, unsigned int> ModInfo::s_ModsByName;
std::map<std::pair<QString, int>, std::vector<unsigned int>> ModInfo::s_ModsByModID;
@@ -287,6 +289,12 @@ void ModInfo::updateFromDisc(const QString &modDirectory,
std::sort(s_Collection.begin(), s_Collection.end(), ModInfo::ByName);
updateIndices();
+
+ for (auto& p : s_Collection) {
+ auto &t = s_Threads.request();
+ t.ptr = p;
+ t.wakeup();
+ }
}
diff --git a/src/modinfo.h b/src/modinfo.h
index b3e75bc4..d3d13d9c 100644
--- a/src/modinfo.h
+++ b/src/modinfo.h
@@ -22,6 +22,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "imodinterface.h"
#include "versioninfo.h"
+#include "envfs.h"
class PluginContainer;
class QDir;
@@ -839,6 +840,36 @@ protected:
private:
+ struct ModThread
+ {
+ ModInfo::Ptr ptr;
+
+ std::condition_variable cv;
+ std::mutex mutex;
+ bool ready = false;
+
+ void wakeup()
+ {
+ {
+ std::scoped_lock lock(mutex);
+ ready = true;
+ }
+
+ cv.notify_one();
+ }
+
+ void run()
+ {
+ std::unique_lock lock(mutex);
+ cv.wait(lock, [&] { return ready; });
+
+ ptr->isValid();
+ ready = false;
+ }
+ };
+
+ static env::ThreadPool<ModThread> s_Threads;
+
static QMutex s_Mutex;
static std::map<std::pair<QString, int>, std::vector<unsigned int> > s_ModsByModID;
static int s_NextID;