Add mutex to protect update thread
This commit is contained in:
parent
c930e316c4
commit
45116d8857
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user