From f7e24f680acbddf9002c87de91cdbcae1eb5f80f Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 7 Oct 2015 01:39:10 +0300 Subject: [PATCH] * add Optimization build type which uses -O3 * create QTimer object in AWDataEngineAggregator class, emit signal to this timer because timers could not be started in the separate thread * increase limit x2 with leaving the thread pool size as was --- sources/CMakeLists.txt | 2 ++ .../plugin/awdataengineaggregator.cpp | 15 ++++++++++++++- .../plugin/awdataengineaggregator.h | 4 ++++ sources/awesome-widget/plugin/awkeys.cpp | 10 ++++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 2390a04..ac0cf06 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -41,12 +41,14 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") + set(CMAKE_CXX_FLAGS_OPTIMIZATION "-O3 -DNDEBUG") # avoid newer gcc warnings add_definitions(-D_DEFAULT_SOURCE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") + set(CMAKE_CXX_FLAGS_OPTIMIZATION "-O3 -DNDEBUG") # linker flags set(CMAKE_EXE_LINKER_FLAGS "-lc++abi") set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi") diff --git a/sources/awesome-widget/plugin/awdataengineaggregator.cpp b/sources/awesome-widget/plugin/awdataengineaggregator.cpp index b5f8a86..a629328 100644 --- a/sources/awesome-widget/plugin/awdataengineaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataengineaggregator.cpp @@ -30,9 +30,16 @@ AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent, const int interv { qCDebug(LOG_AW); + // timer events + m_timer = new QTimer(this); + m_timer->setSingleShot(true); + setInterval(interval); initDataEngines(); connectVisualization(); + + connect(this, SIGNAL(startTimer()), m_timer, SLOT(start())); + connect(m_timer, SIGNAL(timeout()), this, SLOT(connectVisualization())); } @@ -41,6 +48,7 @@ AWDataEngineAggregator::~AWDataEngineAggregator() qCDebug(LOG_AW); m_dataEngines.clear(); + if (m_timer != nullptr) delete m_timer; } @@ -50,6 +58,7 @@ void AWDataEngineAggregator::setInterval(const int _interval) qCDebug(LOG_AW) << "Interval" << _interval; m_interval = _interval; + m_timer->setInterval(5 * _interval); } @@ -57,6 +66,7 @@ void AWDataEngineAggregator::connectVisualization() { qCDebug(LOG_AW); +// reconnectSources(); connect(this, SIGNAL(updateData(QString, QVariantMap)), parent(), SLOT(dataUpdated(QString, QVariantMap))); @@ -70,8 +80,11 @@ void AWDataEngineAggregator::disconnectVisualization() disconnect(this, SIGNAL(updateData(QString, QVariantMap)), parent(), SLOT(dataUpdated(QString, QVariantMap))); +// m_dataEngines.clear(); - return QTimer::singleShot(5 * m_interval, this, SLOT(connectVisualization())); + // HACK run timer in the main thread since a timer could not be started from + // the different thread + return emit(startTimer()); } diff --git a/sources/awesome-widget/plugin/awdataengineaggregator.h b/sources/awesome-widget/plugin/awdataengineaggregator.h index 198295c..0d872ac 100644 --- a/sources/awesome-widget/plugin/awdataengineaggregator.h +++ b/sources/awesome-widget/plugin/awdataengineaggregator.h @@ -23,6 +23,8 @@ #include +class QTimer; + class AWDataEngineAggregator : public QObject { Q_OBJECT @@ -35,6 +37,7 @@ public: void setInterval(const int _interval); signals: + void startTimer(); void updateData(const QString sourceName, const QVariantMap sdata); public slots: @@ -52,6 +55,7 @@ private: void initDataEngines(); QHash m_dataEngines; int m_interval; + QTimer *m_timer = nullptr; }; diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 911d2ea..8f4b24a 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -49,7 +49,7 @@ AWKeys::AWKeys(QObject *parent) #ifdef BUILD_FUTURE // thread pool - queueLimit = QThread::idealThreadCount(); + queueLimit = 2 * QThread::idealThreadCount(); threadPool = new QThreadPool(this); #endif /* BUILD_FUTURE */ @@ -115,11 +115,9 @@ void AWKeys::initKeys(const QString currentPattern, const int interval, const in } else dataEngineAggregator->setInterval(interval); #ifdef BUILD_FUTURE - // queue limit. It may be configured by using QUEUE_LIMIT cmake limit flag. - // In other hand since I'm using global thread pool, it makes sense to limit - // queue by QThread::idealThreadCount() value - queueLimit = limit == 0 ? QThread::idealThreadCount() : limit; - threadPool->setMaxThreadCount(queueLimit); + int rawLimit = (limit == 0 ? QThread::idealThreadCount() : limit); + queueLimit = 2 * rawLimit; + threadPool->setMaxThreadCount(rawLimit); #endif /* BUILD_FUTURE */ updateCache();