mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 16:31:31 +00:00
Ensures proper thread confinement for updateStatusBarText
.
This commit is contained in:
parent
a2db6ddea5
commit
7c05b1788e
@ -1338,24 +1338,25 @@ void MainWindow::addActivityObserver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::register_led(const std::string &name) {
|
void MainWindow::register_led(const std::string &name) {
|
||||||
|
std::lock_guard guard(ledStatusesLock);
|
||||||
ledStatuses[name] = false;
|
ledStatuses[name] = false;
|
||||||
updateStatusBarText();
|
QMetaObject::invokeMethod(this, "updateStatusBarText");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::set_led_status(const std::string &name, bool isLit) {
|
void MainWindow::set_led_status(const std::string &name, bool isLit) {
|
||||||
|
std::lock_guard guard(ledStatusesLock);
|
||||||
ledStatuses[name] = isLit;
|
ledStatuses[name] = isLit;
|
||||||
updateStatusBarText(); // Assumption here: Qt's attempt at automatic thread confinement will work here.
|
QMetaObject::invokeMethod(this, "updateStatusBarText");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateStatusBarText() {
|
void MainWindow::updateStatusBarText() {
|
||||||
QString fullText;
|
QString fullText;
|
||||||
bool isFirst = true;
|
std::lock_guard guard(ledStatusesLock);
|
||||||
for(const auto &pair: ledStatuses) {
|
for(const auto &pair: ledStatuses) {
|
||||||
if(!isFirst) fullText += " | ";
|
if(!fullText.isEmpty()) fullText += " | ";
|
||||||
fullText += QString::fromStdString(pair.first);
|
fullText += QString::fromStdString(pair.first);
|
||||||
fullText += " ";
|
fullText += " ";
|
||||||
fullText += pair.second ? "■" : "□";
|
fullText += pair.second ? "■" : "□";
|
||||||
isFirst = false;
|
|
||||||
}
|
}
|
||||||
statusBar()->showMessage(fullText);
|
statusBar()->showMessage(fullText);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "audiobuffer.h"
|
#include "audiobuffer.h"
|
||||||
@ -80,6 +81,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void startMachine();
|
void startMachine();
|
||||||
|
void updateStatusBarText();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void start_appleII();
|
void start_appleII();
|
||||||
@ -144,9 +146,11 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
|||||||
|
|
||||||
void register_led(const std::string &) override;
|
void register_led(const std::string &) override;
|
||||||
void set_led_status(const std::string &, bool) override;
|
void set_led_status(const std::string &, bool) override;
|
||||||
|
|
||||||
|
std::recursive_mutex ledStatusesLock;
|
||||||
std::map<std::string, bool> ledStatuses;
|
std::map<std::string, bool> ledStatuses;
|
||||||
|
|
||||||
void addActivityObserver();
|
void addActivityObserver();
|
||||||
void updateStatusBarText();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user