Skip to content

Commit

Permalink
fix: Fixed multi-thread resource contention issue
Browse files Browse the repository at this point in the history
Additional protective lock
  • Loading branch information
Kakueeen authored and deepin-mozart committed May 17, 2024
1 parent ae314c6 commit 76f435c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/plugins/binarytools/configure/binarytoolsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ using namespace dpfservice;

QString ToolProcess::readAllStandardOutput()
{
return stdOut;
QMutexLocker lk(&mutex);
return std::move(stdOut);
}

QString ToolProcess::readAllStandardError()
{
return stdError;
QMutexLocker lk(&mutex);
return std::move(stdError);
}

void ToolProcess::start(const QString &id)
Expand All @@ -57,10 +59,12 @@ void ToolProcess::start(const QString &id)
connect(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
this, std::bind(&ToolProcess::finished, this, id, std::placeholders::_1, std::placeholders::_2));
connect(&process, &QProcess::readyReadStandardOutput, this, [=] {
QMutexLocker lk(&mutex);
stdOut += process.readAllStandardOutput();
Q_EMIT readyReadStandardOutput(id);
});
connect(&process, &QProcess::readyReadStandardError, this, [=] {
QMutexLocker lk(&mutex);
stdError += process.readAllStandardError();
Q_EMIT readyReadStandardError(id);
});
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/binarytools/configure/binarytoolsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QMenu>
#include <QProcess>
#include <QThread>
#include <QMutex>

namespace dpfservice {
class WindowService;
Expand Down Expand Up @@ -48,6 +49,7 @@ public Q_SLOTS:
QString workingDir;
QProcessEnvironment environment;

QMutex mutex;
QString stdOut;
QString stdError;
QProcess process;
Expand Down

0 comments on commit 76f435c

Please sign in to comment.