Add mutex to protect update thread

This commit is contained in:
BlackMark 2020-07-17 18:35:38 +02:00
parent c930e316c4
commit 45116d8857
2 changed files with 10 additions and 0 deletions

View File

@ -61,6 +61,8 @@ void MainWindow::enumSensors()
void MainWindow::enumMonitors()
{
m_mtx.lock();
m_ui.monitorDropdown->clear();
auto monitors = enumerateMonitors();
@ -70,6 +72,8 @@ void MainWindow::enumMonitors()
m_ui.monitorDropdown->addItem(monitor.getName());
m_monitors.push_back({std::move(monitor), 0.f, 1.f, currentBrightness, false});
}
m_mtx.unlock();
}
void MainWindow::loadIcons()
@ -269,6 +273,8 @@ void MainWindow::updateCurrentMonitorGUI(int index)
void MainWindow::updateState()
{
m_mtx.lock();
qDebug(ltr("Updating state"));
bool sensorError = false;
@ -322,6 +328,8 @@ void MainWindow::updateState()
if(m_trayIcon) {
m_trayIcon->setToolTip(tr("AdaptiveBrightness - %1%").arg(brightness * 100, 0, 'f', 0));
}
m_mtx.unlock();
}
bool MainWindow::setMonitorBrightness(float& brightness)

View File

@ -8,6 +8,7 @@
#include <QIcon>
#include <QMainWindow>
#include <QMenu>
#include <QMutex>
#include <QSlider>
#include <QSystemTrayIcon>
#include <QThread>
@ -63,6 +64,7 @@ class MainWindow : public QMainWindow {
QThread* m_timerThread = nullptr;
QTimer* m_timer = nullptr;
QMutex m_mtx;
struct SensorData {
Sensor driver;