mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 16:14:35 +02:00
Improve logging system termination. Send a signal and wait until done.
This commit is contained in:
parent
d722650806
commit
24d4f87341
2 changed files with 47 additions and 4 deletions
|
@ -45,26 +45,46 @@ namespace Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteWorker::sync() {
|
void WriteWorker::sync() {
|
||||||
//qDebug() << "Forcing settings sync";
|
//qCDebug(settings_writer) << "Forcing settings sync";
|
||||||
init();
|
init();
|
||||||
_qSettings->sync();
|
_qSettings->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteWorker::threadFinished() {
|
||||||
|
qCDebug(settings_writer) << "Settings write worker syncing and terminating";
|
||||||
|
sync();
|
||||||
|
this->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteWorker::terminate() {
|
||||||
|
qCDebug(settings_writer) << "Settings write worker being asked to terminate. Syncing and terminating.";
|
||||||
|
sync();
|
||||||
|
this->deleteLater();
|
||||||
|
QThread::currentThread()->exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
Manager::Manager(QObject *parent) {
|
Manager::Manager(QObject *parent) {
|
||||||
WriteWorker *worker = new WriteWorker();
|
WriteWorker *worker = new WriteWorker();
|
||||||
|
|
||||||
// We operate purely from memory, and forward all changes to a thread that has writing the
|
// We operate purely from memory, and forward all changes to a thread that has writing the
|
||||||
// settings as its only job.
|
// settings as its only job.
|
||||||
|
|
||||||
qDebug() << "Initializing settings write thread";
|
qCDebug(settings_manager) << "Initializing settings write thread";
|
||||||
|
|
||||||
_workerThread.setObjectName("Settings Writer");
|
_workerThread.setObjectName("Settings Writer");
|
||||||
worker->moveToThread(&_workerThread);
|
worker->moveToThread(&_workerThread);
|
||||||
connect(&_workerThread, &QThread::started, worker, &WriteWorker::start, Qt::QueuedConnection);
|
// connect(&_workerThread, &QThread::started, worker, &WriteWorker::start, Qt::QueuedConnection);
|
||||||
connect(&_workerThread, &QThread::finished, worker, &QObject::deleteLater, Qt::QueuedConnection);
|
|
||||||
|
// All normal connections are queued, so that we're sure they happen asynchronously.
|
||||||
|
connect(&_workerThread, &QThread::finished, worker, &WriteWorker::threadFinished, Qt::QueuedConnection);
|
||||||
connect(this, &Manager::valueChanged, worker, &WriteWorker::setValue, Qt::QueuedConnection);
|
connect(this, &Manager::valueChanged, worker, &WriteWorker::setValue, Qt::QueuedConnection);
|
||||||
connect(this, &Manager::keyRemoved, worker, &WriteWorker::removeKey, Qt::QueuedConnection);
|
connect(this, &Manager::keyRemoved, worker, &WriteWorker::removeKey, Qt::QueuedConnection);
|
||||||
connect(this, &Manager::syncRequested, worker, &WriteWorker::sync, Qt::QueuedConnection);
|
connect(this, &Manager::syncRequested, worker, &WriteWorker::sync, Qt::QueuedConnection);
|
||||||
|
|
||||||
|
// This one is blocking because we want to wait until it's actually processed.
|
||||||
|
connect(this, &Manager::terminationRequested, worker, &WriteWorker::terminate, Qt::BlockingQueuedConnection);
|
||||||
|
|
||||||
|
|
||||||
_workerThread.start();
|
_workerThread.start();
|
||||||
|
|
||||||
// Load all current settings
|
// Load all current settings
|
||||||
|
@ -136,6 +156,16 @@ namespace Setting {
|
||||||
emit syncRequested();
|
emit syncRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::terminateThread() {
|
||||||
|
qCDebug(settings_manager) << "Terminating settings writer thread";
|
||||||
|
|
||||||
|
emit terminationRequested(); // This blocks
|
||||||
|
|
||||||
|
_workerThread.exit();
|
||||||
|
_workerThread.wait(THREAD_TERMINATION_TIMEOUT);
|
||||||
|
qCDebug(settings_manager) << "Settings writer terminated";
|
||||||
|
}
|
||||||
|
|
||||||
QString Manager::fileName() const {
|
QString Manager::fileName() const {
|
||||||
return resultWithReadLock<QString>([&] {
|
return resultWithReadLock<QString>([&] {
|
||||||
return _fileName;
|
return _fileName;
|
||||||
|
|
|
@ -80,6 +80,18 @@ namespace Setting {
|
||||||
*/
|
*/
|
||||||
void sync();
|
void sync();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the thread is terminating
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void threadFinished();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Thread is being asked to finish work and quit
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void terminate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
@ -194,6 +206,7 @@ namespace Setting {
|
||||||
void valueChanged(const QString key, QVariant value);
|
void valueChanged(const QString key, QVariant value);
|
||||||
void keyRemoved(const QString key);
|
void keyRemoved(const QString key);
|
||||||
void syncRequested();
|
void syncRequested();
|
||||||
|
void terminationRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QString, Interface*> _handles;
|
QHash<QString, Interface*> _handles;
|
||||||
|
|
Loading…
Reference in a new issue