Skip to content

Commit

Permalink
Thread pool optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Aug 8, 2022
1 parent 6d6db46 commit 7b73735
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qpp/prefetch/Source/Core/Thread/read_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ QMutex ReadThread::printLock(QMutex::NonRecursive);
QStringList ReadThread::excludeFolders = QStringList();
QStringList ReadThread::priorityIncludePatterns = QStringList();
bool ReadThread::pause = false;
QList<QRunnable *> ReadThread::pendingDeleteThread = QList<QRunnable *>();

ReadThread::ReadThread(QString filePath)
{
Expand Down Expand Up @@ -65,6 +66,12 @@ bool ReadThread::run_SearchInclude()
return false;
}

void ReadThread::run_RequestDelete()
{
QRunnable *currentThreadPointer = this;
pendingDeleteThread.append(currentThreadPointer);
}

void ReadThread::run_read()
{
// Read file
Expand Down Expand Up @@ -97,6 +104,7 @@ void ReadThread::run()
{
if (run_SearchExclude())
{
run_RequestDelete();
return;
}
}
Expand Down
6 changes: 6 additions & 0 deletions qpp/prefetch/Source/Core/Thread/read_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ReadThread : public QRunnable
// each read will not happen but return immediately
static bool pause;

// A thread that report it can be delete goes here
static QList<QRunnable *> pendingDeleteThread;

void run() override;

private:
Expand All @@ -48,6 +51,9 @@ class ReadThread : public QRunnable
// true: File is excluded
bool run_SearchExclude();

// This file is excluded, delete read thread after first run
void run_RequestDelete();

// Prefetch file
void run_read();
};
10 changes: 10 additions & 0 deletions qpp/prefetch/Source/Core/read_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,18 @@ bool ReadFile::start_runThreadPool(int rescanInterval)
readThreadPool->start(readThreadQueue[i]);
}

// Delete excluded file thread
readThreadPool->waitForDone();

auto dbg_PendingDeleteThread = &ReadThread::pendingDeleteThread;
for (int i = 0; i < ReadThread::pendingDeleteThread.size(); ++i)
{
auto threadPointer = ReadThread::pendingDeleteThread[i];
readThreadQueue.removeOne(threadPointer);
delete threadPointer;
}
ReadThread::pendingDeleteThread.clear();

// Get code execute time
auto threadPoolTimeConsumedMiliseconds = threadPoolTimer.elapsed();
auto threadPoolTimeConsumedFormatedString = QTime()
Expand Down

0 comments on commit 7b73735

Please sign in to comment.