Skip to content

Commit

Permalink
fix: 修复非GUI线程调用 update() 函数
Browse files Browse the repository at this point in the history
非GUI线程间接调用了update()函数, update()内部的
处理函数会调用markDirty()更新脏控件列表,但是
dirtyWidget(QVector)在多线程访问时可能无法正确
更新数据,导致widget的inDirtyList标识为true,
但dirtyWidget后续未正确的复位标识。
在QWidgetBackingStore::doSync()中一直无法正确的
将绘制数据刷新。
移动onStatInfoUpdated()计算逻辑到子线程类中,
界面更新移动到GUI线程.

Log: 修复界面刷新显示问题
Bug: https://pms.uniontech.com/bug-view-247719.html
Change-Id: Ic033097bb7010363bc4ee1768340812231b9c4d1
  • Loading branch information
rb-union authored and deepin-bot[bot] committed Apr 26, 2024
1 parent 00e9738 commit 9ec42bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
24 changes: 4 additions & 20 deletions deepin-system-monitor-main/gui/process_page_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ void ProcessPageWidget::initConnections()

// update process summary text when process summary info updated background
auto *monitor = ThreadManager::instance()->thread<SystemMonitorThread>(BaseThread::kSystemMonitorThread)->systemMonitorInstance();
connect(monitor, &SystemMonitor::statInfoUpdated, this, &ProcessPageWidget::onStatInfoUpdated, Qt::DirectConnection);
// Note: do not update on non-GUI thread.
connect(monitor, &SystemMonitor::appAndProcCountUpdate, this, &ProcessPageWidget::onAppAndProcCountUpdated);

auto *dAppHelper = DApplicationHelper::instance();
// change text color dynamically on theme type change, if not do this way, text color wont synchronize with theme type
Expand Down Expand Up @@ -409,27 +410,10 @@ void ProcessPageWidget::createWindowKiller()
&ProcessPageWidget::popupKillConfirmDialog);
}

void ProcessPageWidget::onStatInfoUpdated()
void ProcessPageWidget::onAppAndProcCountUpdated(int appCount, int procCount)
{
QApplication::processEvents();
const QString &buf = DApplication::translate("Process.Summary", kProcSummaryTemplateText);

ProcessSet *processSet = ProcessDB::instance()->processSet();
//记录所有进程数量
const QList<pid_t> &newpidlst = processSet->getPIDList();
m_iallProcNum = newpidlst.size();
int appCount = 0;
for (const auto &pid : newpidlst) {
auto process = processSet->getProcessById(pid);
if (process.appType() == kFilterApps)
appCount++;
}
m_procViewModeSummary->setText(buf.arg(appCount).arg(m_iallProcNum));
m_model = CPUInfoModel::instance();

// CPUPerformance = (m_model->cpuSet()->maxFreq() > CPU_FREQUENCY_STANDARD) ? High : Low;
//qInfo() << m_model->cpuSet()->maxFreq() << (m_model->cpuSet()->maxFreq() > CPU_FREQUENCY_STANDARD) << CPUPerformance;

m_procViewModeSummary->setText(buf.arg(appCount).arg(procCount));
}

// change icon theme when theme changed
Expand Down
4 changes: 2 additions & 2 deletions deepin-system-monitor-main/gui/process_page_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ private Q_SLOTS:
void changeIconTheme(DApplicationHelper::ColorType themeType);

/**
* @brief 列表数据刷新
* @brief 列表数据刷新,更新应用和进程统计
*/
void onStatInfoUpdated();
void onAppAndProcCountUpdated(int appCount, int procCount);

/**
* @brief 详情页切换
Expand Down
21 changes: 20 additions & 1 deletion deepin-system-monitor-main/system/system_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ SystemMonitor::SystemMonitor(QObject *parent)
, m_processDB(new ProcessDB(this))
{
m_sysInfo->readSysInfoStatic();

}

SystemMonitor::~SystemMonitor()
Expand Down Expand Up @@ -84,6 +83,7 @@ void SystemMonitor::timerEvent(QTimerEvent *event)
m_processDB->update();
} else {
emit statInfoUpdated();
recountAppAndProcess();
}
if(cnt++ >250)
cnt = 0;
Expand All @@ -97,6 +97,25 @@ void SystemMonitor::updateSystemMonitorInfo()
m_processDB->update();

emit statInfoUpdated();
recountAppAndProcess();
}

/**
@brief Count current apps and processes on SystemMonitor child thread.
*/
void SystemMonitor::recountAppAndProcess()
{
ProcessSet *processSet = m_processDB->processSet();
// count all app
const QList<pid_t> &newpidlst = processSet->getPIDList();
int appCount = 0;
for (const auto &pid : newpidlst) {
auto process = processSet->getProcessById(pid);
if (process.appType() == kFilterApps)
appCount++;
}

emit appAndProcCountUpdate(appCount, newpidlst.size());
}

} // namespace system
Expand Down
2 changes: 2 additions & 0 deletions deepin-system-monitor-main/system/system_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SystemMonitor : public QObject

signals:
void statInfoUpdated();
void appAndProcCountUpdate(int appCount, int procCount);

public:
explicit SystemMonitor(QObject *parent = nullptr);
Expand All @@ -48,6 +49,7 @@ class SystemMonitor : public QObject

private:
void updateSystemMonitorInfo();
void recountAppAndProcess();

private:
SysInfo *m_sysInfo;
Expand Down

0 comments on commit 9ec42bd

Please sign in to comment.