logger: fix thread deadlock

This commit is contained in:
Dusan Zivkovic 2020-03-06 11:52:54 +01:00 committed by Beat Küng
parent 4698a09b98
commit d7a9b123e6
1 changed files with 6 additions and 2 deletions

View File

@ -295,8 +295,12 @@ void LogWriterFile::run()
/* Wait for a call to notify(), which indicates new data is available. /* Wait for a call to notify(), which indicates new data is available.
* Note that at this point there could already be new data available (because of a longer write), * Note that at this point there could already be new data available (because of a longer write),
* and calling pthread_cond_wait() will still wait for the next notify(). But this is generally * and calling pthread_cond_wait() will still wait for the next notify(). But this is generally
* not an issue because notify() is called regularly. */ * not an issue because notify() is called regularly.
pthread_cond_wait(&_cv, &_mtx); * If the logger was switched off in the meantime, do not wait for data, instead run this loop
* once more to write remaining data and close the file. */
if (_buffers[0]._should_run) {
pthread_cond_wait(&_cv, &_mtx);
}
} }
// go back to idle // go back to idle