diff options
Diffstat (limited to 'src/directoryrefresher.cpp')
| -rw-r--r-- | src/directoryrefresher.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index 20d6a52b..a59ddf9d 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -203,8 +203,8 @@ struct ModThread std::wstring modName;
std::wstring path;
int prio = -1;
- env::Directory* dir = nullptr;
DirectoryStats* stats = nullptr;
+ env::DirectoryWalker walker;
std::condition_variable cv;
std::mutex mutex;
@@ -212,7 +212,11 @@ struct ModThread void wakeup()
{
- ready = true;
+ {
+ std::scoped_lock lock(mutex);
+ ready = true;
+ }
+
cv.notify_one();
}
@@ -222,7 +226,7 @@ struct ModThread cv.wait(lock, [&]{ return ready; });
SetThisThreadName(QString::fromStdWString(modName + L" refresher"));
- ds->addFromOrigin(modName, path, prio, *stats);
+ ds->addFromOrigin(walker, modName, path, prio, *stats);
/*if (Settings::instance().archiveParsing()) {
addModBSAToStructure(
@@ -237,6 +241,9 @@ struct ModThread }
};
+env::ThreadPool<ModThread> g_threads;
+
+
void dumpStats(std::vector<DirectoryStats>& stats)
{
static int run = 0;
@@ -268,35 +275,33 @@ void DirectoryRefresher::addMultipleModsFilesToStructure( MOShared::DirectoryEntry *directoryStructure,
const std::vector<EntryInfo>& entries, bool emitProgress)
{
- std::vector<env::Directory> dirs(entries.size());
std::vector<DirectoryStats> stats(entries.size());
+ g_threads.setMax(m_threadCount);
+
{
TimeThis tt("walk dirs");
- env::ThreadPool<ModThread> threads(m_threadCount);
-
for (std::size_t i=0; i<entries.size(); ++i) {
const auto& e = entries[i];
const int prio = static_cast<int>(i + 1);
+ stats[i].mod = entries[i].modName.toStdString();
+
try
{
if (e.stealFiles.length() > 0) {
stealModFilesIntoStructure(
directoryStructure, e.modName, prio, e.absolutePath, e.stealFiles);
} else {
- auto& mt = threads.request();
+ auto& mt = g_threads.request();
mt.ds = directoryStructure;
mt.modName = entries[i].modName.toStdWString();
mt.path = QDir::toNativeSeparators(e.absolutePath).toStdWString();
mt.prio = prio;
- mt.dir = &dirs[i];
mt.stats = &stats[i];
- stats[i].mod = entries[i].modName.toStdString();
-
mt.wakeup();
}
} catch (const std::exception& ex) {
@@ -308,7 +313,7 @@ void DirectoryRefresher::addMultipleModsFilesToStructure( }
}
- threads.join();
+ g_threads.waitForAll();
}
dumpStats(stats);
@@ -347,12 +352,12 @@ void DirectoryRefresher::refresh() m_DirectoryStructure->getFileRegister()->sortOrigins();
- emit progress(100);
-
cleanStructure(m_DirectoryStructure);
+ }
- emit refreshed();
+ emit progress(100);
- //logcounts("after refresh");
- }
+ emit refreshed();
+
+ //logcounts("after refresh");
}
|
