shared: Begin DirScanWorker
This commit is contained in:
50
shared/dirscanworker.cpp
Normal file
50
shared/dirscanworker.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <QThread>
|
||||
#include "dirscanworker.h"
|
||||
#include "logger.h"
|
||||
DirScanWorker::DirScanWorker(ConcurrentQueue<QString> &queue, ConcurrentQueue<QString> &resultQueue,
|
||||
QStringList ignorePattern, unsigned int progressReportThreshold,
|
||||
std::atomic<bool> &stopToken)
|
||||
{
|
||||
this->queue = &queue;
|
||||
this->resultQueue = &resultQueue;
|
||||
this->ignorePattern = ignorePattern;
|
||||
this->progressReportThreshold = progressReportThreshold;
|
||||
this->stopToken = &stopToken;
|
||||
setAutoDelete(false);
|
||||
}
|
||||
|
||||
void DirScanWorker::run()
|
||||
{
|
||||
unsigned int currentProgress = 0;
|
||||
QString path;
|
||||
/* TODO: if we have e. g. only one path, then only one thread will scan this path.
|
||||
*
|
||||
* Thus, we must resubmit to the queue directories so other threads can help
|
||||
the current one (requires a new logic for threads in ParallelDirScanner). Alterantively,
|
||||
start new DirScanWorkers ourselves here... */
|
||||
while(queue->dequeue(path))
|
||||
{
|
||||
QDirIterator iterator(path, ignorePattern, QDir::Files, QDirIterator::Subdirectories);
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
this->results.append(iterator.next());
|
||||
++currentProgress;
|
||||
if(currentProgress == progressReportThreshold)
|
||||
{
|
||||
if(this->stopToken->load(std::memory_order_relaxed))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->resultQueue->enqueue(this->results);
|
||||
emit progress(results.length());
|
||||
currentProgress = 0;
|
||||
this->results.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
this->resultQueue->enqueue(this->results);
|
||||
emit progress(results.length());
|
||||
this->results.clear();
|
||||
emit finished();
|
||||
}
|
Reference in New Issue
Block a user