mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 23:52:26 +00:00
Attempts to ensure clean shutdown.
This commit is contained in:
parent
d08ffd6c8b
commit
ac732e2e7b
@ -24,6 +24,11 @@ class FunctionThread: public QThread {
|
|||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||||
|
while(isRunning());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::function<void(void)> function;
|
std::function<void(void)> function;
|
||||||
};
|
};
|
||||||
|
@ -66,9 +66,7 @@ MainWindow::~MainWindow() {
|
|||||||
// Stop the audio output, and its thread.
|
// Stop the audio output, and its thread.
|
||||||
if(audioOutput) {
|
if(audioOutput) {
|
||||||
audioOutput->stop();
|
audioOutput->stop();
|
||||||
|
audioThread.stop();
|
||||||
audioThread.quit();
|
|
||||||
while(audioThread.isRunning());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the timer.
|
// Stop the timer.
|
||||||
|
@ -10,7 +10,7 @@ Timer::Timer(QObject *parent) : QObject(parent) {
|
|||||||
// Set up the emulation timer. Bluffer's guide: the QTimer will post an
|
// Set up the emulation timer. Bluffer's guide: the QTimer will post an
|
||||||
// event to an event loop. QThread is a thread with an event loop.
|
// event to an event loop. QThread is a thread with an event loop.
|
||||||
// My class, Timer, will be wired up to receive the QTimer's events.
|
// My class, Timer, will be wired up to receive the QTimer's events.
|
||||||
timer = std::make_unique<QTimer>(&thread);
|
timer = std::make_unique<QTimer>();
|
||||||
timer->setInterval(1);
|
timer->setInterval(1);
|
||||||
|
|
||||||
connect(timer.get(), SIGNAL(timeout()), this, SLOT(tick()), Qt::DirectConnection);
|
connect(timer.get(), SIGNAL(timeout()), this, SLOT(tick()), Qt::DirectConnection);
|
||||||
@ -28,7 +28,6 @@ void Timer::startWithMachine(MachineTypes::TimedMachine *machine, std::mutex *ma
|
|||||||
void Timer::tick() {
|
void Timer::tick() {
|
||||||
const auto now = Time::nanos_now();
|
const auto now = Time::nanos_now();
|
||||||
const auto duration = std::min(now - lastTickNanos, int64_t(500'000'000));
|
const auto duration = std::min(now - lastTickNanos, int64_t(500'000'000));
|
||||||
// qDebug() << duration << " [not " << now - lastTickNanos << "]";
|
|
||||||
lastTickNanos = now;
|
lastTickNanos = now;
|
||||||
|
|
||||||
std::lock_guard lock_guard(*machineMutex);
|
std::lock_guard lock_guard(*machineMutex);
|
||||||
@ -36,8 +35,6 @@ void Timer::tick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Timer::~Timer() {
|
Timer::~Timer() {
|
||||||
// Stop the timer, then ask the QThread to exit and wait for it to do so.
|
QMetaObject::invokeMethod(timer.get(), "stop", Qt::QueuedConnection);
|
||||||
timer->stop();
|
thread.stop();
|
||||||
thread.exit();
|
|
||||||
while(thread.isRunning());
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user