Ensure we don't hang if the QML thread doesn't shutdown

This commit is contained in:
Brad Davis 2015-12-31 15:23:39 -08:00
parent 67e32cc1f0
commit a0196f0cde

View file

@ -254,10 +254,33 @@ private:
_quit = true;
}
static const uint64_t MAX_SHUTDOWN_WAIT_SECS = 5;
void stop() {
QMutexLocker lock(&_mutex);
post(STOP);
_cond.wait(&_mutex);
if (_thread.isRunning()) {
qDebug() << "Stopping QML render thread " << _thread.currentThreadId();
{
QMutexLocker lock(&_mutex);
post(STOP);
}
auto start = usecTimestampNow();
auto now = usecTimestampNow();
bool shutdownClean = false;
while (now - start < (MAX_SHUTDOWN_WAIT_SECS * USECS_PER_SECOND)) {
QMutexLocker lock(&_mutex);
if (_cond.wait(&_mutex, MSECS_PER_SECOND)) {
shutdownClean = true;
break;
}
now = usecTimestampNow();
}
if (!shutdownClean) {
qWarning() << "Failed to shut down the QML render thread";
}
} else {
qDebug() << "QML render thread already completed";
}
}
bool allowNewFrame(uint8_t fps) {