Merge pull request #71 from mammonsama666/cpu
fix(read queue thread): Fix bug of excessive CPU usage.
This commit is contained in:
commit
1df1a05e58
|
@ -162,7 +162,7 @@ void MainWindow::initUi()
|
|||
connect(m_settingsWidget, &SettingsWidget::settingWidgetClosed, this, [ = ]() {
|
||||
QTimer::singleShot(100, this, [ = ] {
|
||||
clearSearchResult();
|
||||
m_search_result_thread->start();
|
||||
// m_search_result_thread->start();
|
||||
this->setWindowState(this->windowState() & ~Qt::WindowMinimized);
|
||||
this->raise();
|
||||
this->showNormal();
|
||||
|
@ -192,10 +192,17 @@ void MainWindow::initUi()
|
|||
&MainWindow::primaryScreenChangedSlot);
|
||||
connect(m_searchLayout, &UkuiSearchBarHLayout::textChanged, this, [ = ](QString text) {
|
||||
if (text == "") {
|
||||
if (m_search_result_thread->isInterruptionRequested()) {
|
||||
m_search_result_thread->requestInterruption();
|
||||
m_search_result_thread->quit();
|
||||
}
|
||||
m_contentFrame->setCurrentIndex(0);
|
||||
} else {
|
||||
m_contentFrame->setCurrentIndex(1);
|
||||
// QTimer::singleShot(50,this,[=](){
|
||||
if (! m_search_result_thread->isInterruptionRequested()) {
|
||||
m_search_result_thread->start();
|
||||
}
|
||||
searchContent(text);
|
||||
// });
|
||||
}
|
||||
|
@ -215,7 +222,7 @@ void MainWindow::bootOptionsFilter(QString opt)
|
|||
this->show();
|
||||
this->raise();
|
||||
this->activateWindow();
|
||||
m_search_result_thread->start();
|
||||
// m_search_result_thread->start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -299,6 +306,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
|||
switch (event->response_type & ~0x80) {
|
||||
case XCB_FOCUS_OUT:
|
||||
this->hide();
|
||||
m_search_result_thread->requestInterruption();
|
||||
m_search_result_thread->quit();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
#include "search-result.h"
|
||||
#include <QTimer>
|
||||
|
||||
SearchResult::SearchResult(QObject * parent) : QThread(parent)
|
||||
{
|
||||
m_mainwindow = static_cast<MainWindow *>(parent);
|
||||
// m_timer = new QTimer;
|
||||
// QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){
|
||||
// qWarning()<<"-------------------------------------------------------";
|
||||
// m_timer->stop();
|
||||
// this->requestInterruption();
|
||||
// });
|
||||
}
|
||||
|
||||
SearchResult::~SearchResult()
|
||||
{
|
||||
|
||||
// if (m_timer) {
|
||||
// delete m_timer;
|
||||
// m_timer = NULL;
|
||||
// }
|
||||
}
|
||||
|
||||
void SearchResult::run()
|
||||
{
|
||||
QTimer * m_timer = new QTimer;
|
||||
int emptyLists = 0;
|
||||
while(!isInterruptionRequested()) {
|
||||
qWarning()<<"--------------------";
|
||||
emptyLists = 0;
|
||||
m_mainwindow->m_searcher->m_mutex1.lock();
|
||||
if (!m_mainwindow->m_search_result_file->isEmpty()) {
|
||||
|
@ -42,5 +52,15 @@ void SearchResult::run()
|
|||
emptyLists ++;
|
||||
m_mainwindow->m_searcher->m_mutex3.unlock();
|
||||
}
|
||||
if (m_timer->isActive() && m_timer->remainingTime() < 0.01) {
|
||||
this->requestInterruption();
|
||||
}
|
||||
if (emptyLists == 3 && !m_timer->isActive()) {
|
||||
m_timer->start();
|
||||
} else if (emptyLists != 3) {
|
||||
m_timer->stop();
|
||||
} else {
|
||||
msleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define SEARCHRESULT_H
|
||||
#include <QThread>
|
||||
#include <QWaitCondition>
|
||||
#include <QTimer>
|
||||
#include "mainwindow.h"
|
||||
|
||||
class SearchResult : public QThread
|
||||
|
@ -15,6 +16,7 @@ protected:
|
|||
|
||||
private:
|
||||
MainWindow * m_mainwindow = nullptr;
|
||||
// QTimer * m_timer = nullptr;
|
||||
|
||||
Q_SIGNALS:
|
||||
void searchResultFile(const QString&);
|
||||
|
|
Loading…
Reference in New Issue