From 76f435c84457688a73e7ec15fa79dbfe220860f7 Mon Sep 17 00:00:00 2001 From: liuzhangjian Date: Fri, 17 May 2024 13:37:40 +0800 Subject: [PATCH] fix: Fixed multi-thread resource contention issue Additional protective lock --- src/plugins/binarytools/configure/binarytoolsmanager.cpp | 8 ++++++-- src/plugins/binarytools/configure/binarytoolsmanager.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/binarytools/configure/binarytoolsmanager.cpp b/src/plugins/binarytools/configure/binarytoolsmanager.cpp index 0a83ea667..f1ebf378e 100644 --- a/src/plugins/binarytools/configure/binarytoolsmanager.cpp +++ b/src/plugins/binarytools/configure/binarytoolsmanager.cpp @@ -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) @@ -57,10 +59,12 @@ void ToolProcess::start(const QString &id) connect(&process, static_cast(&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); }); diff --git a/src/plugins/binarytools/configure/binarytoolsmanager.h b/src/plugins/binarytools/configure/binarytoolsmanager.h index 8f7941b6f..ac742f3d7 100644 --- a/src/plugins/binarytools/configure/binarytoolsmanager.h +++ b/src/plugins/binarytools/configure/binarytoolsmanager.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace dpfservice { class WindowService; @@ -48,6 +49,7 @@ public Q_SLOTS: QString workingDir; QProcessEnvironment environment; + QMutex mutex; QString stdOut; QString stdError; QProcess process;