Sleep if Decode fails instead of spinning

This commit is contained in:
Isaac Connor
2022-06-17 16:32:05 -04:00
parent 3d9e8ae83c
commit bd711c5230

View File

@@ -22,6 +22,13 @@ void DecoderThread::Run() {
Debug(2, "DecoderThread::Run() for %d", monitor_->Id());
while (!(terminate_ or zm_terminate)) {
monitor_->Decode();
if (!monitor_->Decode()) {
if (!(terminate_ or zm_terminate)) {
// We only sleep when Decode returns false because it is an error condition and we will spin like mad if it persists.
Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count()));
std::this_thread::sleep_for(sleep_for);
}
}
}
}