mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +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();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||
while(isRunning());
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void(void)> function;
|
||||
};
|
||||
|
@ -66,9 +66,7 @@ MainWindow::~MainWindow() {
|
||||
// Stop the audio output, and its thread.
|
||||
if(audioOutput) {
|
||||
audioOutput->stop();
|
||||
|
||||
audioThread.quit();
|
||||
while(audioThread.isRunning());
|
||||
audioThread.stop();
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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.
|
||||
timer = std::make_unique<QTimer>(&thread);
|
||||
timer = std::make_unique<QTimer>();
|
||||
timer->setInterval(1);
|
||||
|
||||
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() {
|
||||
const auto now = Time::nanos_now();
|
||||
const auto duration = std::min(now - lastTickNanos, int64_t(500'000'000));
|
||||
// qDebug() << duration << " [not " << now - lastTickNanos << "]";
|
||||
lastTickNanos = now;
|
||||
|
||||
std::lock_guard lock_guard(*machineMutex);
|
||||
@ -36,8 +35,6 @@ void Timer::tick() {
|
||||
}
|
||||
|
||||
Timer::~Timer() {
|
||||
// Stop the timer, then ask the QThread to exit and wait for it to do so.
|
||||
timer->stop();
|
||||
thread.exit();
|
||||
while(thread.isRunning());
|
||||
QMetaObject::invokeMethod(timer.get(), "stop", Qt::QueuedConnection);
|
||||
thread.stop();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user