Skip to content

Commit

Permalink
fix: Error in Destructuring and Exiting Iteration Thread
Browse files Browse the repository at this point in the history
Modify that only cached iteration threads bind this exit signal

Log: Error in Destructuring and Exiting Iteration Thread
Bug: https://pms.uniontech.com/bug-view-259807.html https://pms.uniontech.com/bug-view-259807.html
  • Loading branch information
liyigang1 authored and deepin-bot[bot] committed Jun 26, 2024
1 parent 729551c commit 53d7183
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,24 @@ RootInfo::~RootInfo()
thread->traversalThread->stop();
thread->traversalThread->wait();
}
// wait old dir iterator thread
for (const auto &thread : discardedThread) {
thread->disconnect();
thread->stop();
thread->wait();
}
}

bool RootInfo::initThreadOfFileData(const QString &key, DFMGLOBAL_NAMESPACE::ItemRoles role, Qt::SortOrder order, bool isMixFileAndFolder)
{
// clear old dir iterator thread
for (auto it = discardedThread.begin(); it != discardedThread.end(); ) {
if (!(*it)->isRunning()) {
it = discardedThread.erase(it);
} else {
it++;
}
}
// create traversal thread
QSharedPointer<DirIteratorThread> traversalThread = traversalThreads.value(key);
bool isGetCache = canCache;
Expand Down Expand Up @@ -144,14 +158,9 @@ int RootInfo::clearTraversalThread(const QString &key, const bool isRefresh)
traversalThread->disconnect(this);
if (traversalThread->isRunning()) {
discardedThread.append(traversalThread);
connect(thread->traversalThread.data(), &TraversalDirThread::finished, this, [this, traversalThread] {
discardedThread.removeAll(traversalThread);
traversalThread->disconnect();
},
Qt::QueuedConnection);
traversaling = false;
}
thread->traversalThread->quit();
thread->traversalThread->stop();
if (traversalThreads.isEmpty())
needStartWatcher = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RootInfo : public QObject
bool initThreadOfFileData(const QString &key,
DFMGLOBAL_NAMESPACE::ItemRoles role, Qt::SortOrder order, bool isMixFileAndFolder);
void startWork(const QString &key, const bool getCache = false);
int clearTraversalThread(const QString &key, const bool isRefresh = false);
int clearTraversalThread(const QString &key, const bool isRefresh);

void reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ TEST_F(UT_RootInfo, ClearTraversalThread)
bool getCache = rootInfoObj->initThreadOfFileData(key, role, order, false);

QString unexistKey("unexistThreadKey");
int threadCount = rootInfoObj->clearTraversalThread(unexistKey);
int threadCount = rootInfoObj->clearTraversalThread(unexistKey, false);
EXPECT_EQ(threadCount, 1);
EXPECT_EQ(rootInfoObj->discardedThread.count(), 0);
EXPECT_FALSE(calledThreadQuit);

threadCount = rootInfoObj->clearTraversalThread(key);
threadCount = rootInfoObj->clearTraversalThread(key, false);
EXPECT_EQ(threadCount, 0);
EXPECT_EQ(rootInfoObj->discardedThread.count(), 1);
EXPECT_TRUE(calledThreadQuit);
Expand Down

0 comments on commit 53d7183

Please sign in to comment.