Skip to content

Commit

Permalink
Remove CPU waste when restore from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Sep 13, 2022
1 parent 834e5c1 commit f222169
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions qpp/prefetch/Source/Core/ReadFile/read_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ReadFile : public QThread

// Queue thread for later use
// Start threadpool after iterate complete to reduce I/O fragment
static void run_scanFolder_createReadFileThread_ququeThread(QString filePath);
static void run_scanFolder_createReadFileThread_ququeThread(QString filePath, bool skipSearch = false);

// Save running sleep thread address for later access on other thread
static SleepThread *sleepThreadAddress;
Expand Down Expand Up @@ -50,7 +50,7 @@ class ReadFile : public QThread
// Convert config file option to QT thread enum
static QMap<QString, QThread::Priority> priorityMap;

// Read all file in QFileInfoList
// Read all file in QFileInfoList
static void run_scanFolder_createReadFileThread(QDir *prefetchFolder);

// Iterated function
Expand Down
4 changes: 3 additions & 1 deletion qpp/prefetch/Source/Core/ReadFile/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ bool ReadFile::run_runThreadPool(int rescanInterval)
return true;
}

void ReadFile::run_scanFolder_createReadFileThread_ququeThread(QString filePath)
void ReadFile::run_scanFolder_createReadFileThread_ququeThread(QString filePath, bool skipSearch)
{
auto readThread = new ReadThread(filePath);
readThread->skipSearch = skipSearch;

ReadFile::readThreadQueue.append(readThread);
}

Expand Down
17 changes: 11 additions & 6 deletions qpp/prefetch/Source/Core/Thread/read_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,20 @@ void ReadThread::run()
return;
}

bool priorityInclude = run_SearchInclude();

// Only search excluded if file not priority included
if (priorityInclude == false)
if (skipSearch == false)
{
if (run_SearchExclude())
bool priorityInclude = run_SearchInclude();

// Only search excluded if file not priority included
if (priorityInclude == false)
{
return;
if (run_SearchExclude())
{
return;
}
}

skipSearch = true;
}

run_read();
Expand Down
4 changes: 4 additions & 0 deletions qpp/prefetch/Source/Core/Thread/read_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class ReadThread : public QRunnable
// Save file path
QString filePath;

// Assume each file is created from cache first
// Modify to false if created from search
bool skipSearch;

private:
// Prevent access stdio at same time
static QMutex printLock;
Expand Down
3 changes: 2 additions & 1 deletion qpp/prefetch/Source/Core/scan_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void ScanCache::loadScanCache(QList<QRunnable *> *readThreadQueueAddress)
auto getSize = Setting::getInt(MetaData, Size, cache);
auto size = getSize.result;

Setting_getOrderedArrayValue_macro(ScanFolder, size, ReadFile::run_scanFolder_createReadFileThread_ququeThread, cache);
#define valueCallback(foo) ReadFile::run_scanFolder_createReadFileThread_ququeThread(foo, true)
Setting_getOrderedArrayValue_macro(ScanFolder, size, valueCallback, cache);
}

void ScanCache::expireCache()
Expand Down

0 comments on commit f222169

Please sign in to comment.