clear up heartbeat code, improve logs in debug builds

This commit is contained in:
Lion Kortlepel
2021-02-28 10:44:35 +01:00
committed by Anonymous275
parent ab44ac8c15
commit 8e4006fc38
2 changed files with 39 additions and 11 deletions

View File

@@ -18,11 +18,16 @@ void THeartbeatThread::operator()() {
Body = GenerateCall();
// a hot-change occurs when a setting has changed, to update the backend of that change.
auto Now = std::chrono::high_resolution_clock::now();
if (((Now - LastNormalUpdateTime) < std::chrono::seconds(5))
|| (Last == Body && (Now - LastNormalUpdateTime) < std::chrono::seconds(30))) {
bool Unchanged = Last == Body;
auto TimePassed = (Now - LastNormalUpdateTime);
auto Threshold = Unchanged ? 30 : 5;
if (TimePassed < std::chrono::seconds(Threshold)) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
continue;
}
#ifdef DEBUG
debug("heartbeat @ " + std::to_string(std::chrono::duration_cast<std::chrono::seconds>(TimePassed).count()));
#endif // DEBUG
Last = Body;
LastNormalUpdateTime = Now;