Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Error in Destructuring and Exiting Iteration Thread #2055

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading