diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2020-12-06 13:55:59 -0500 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-12-08 09:26:41 +0000 |
commit | 6574fbd8819f11d9bdcbe5fb32a8ec76f09ab80a (patch) | |
tree | 3954b9ce19c19e43736701b3f5fdea49ab39870e | |
parent | Rename _channelName to channelName. (diff) | |
download | online-6574fbd8819f11d9bdcbe5fb32a8ec76f09ab80a.tar.gz online-6574fbd8819f11d9bdcbe5fb32a8ec76f09ab80a.zip |
wsd: use chrono datatypes as much as possible
std::chrono handles unit conversion handsomely
and where there could be logical errors, the
compiler errors out. We only ever need to
use raw integer or double values to interface
C functions and possibly for IO.
Change-Id: I5c2b43c36bd69840f1a4172e9898666c4d68c567
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
-rw-r--r-- | wsd/DocumentBroker.cpp | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 867dc791bb..9d9f31cb35 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -234,11 +234,12 @@ void DocumentBroker::pollThread() #if !MOBILEAPP do { - static const int timeoutMs = COMMAND_TIMEOUT_MS * 5; + static constexpr std::chrono::milliseconds timeoutMs(COMMAND_TIMEOUT_MS * 5); _childProcess = getNewChild_Blocks(); - if (_childProcess || - std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - - _threadStart).count() > timeoutMs) + if (_childProcess + || std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::steady_clock::now() - _threadStart) + > timeoutMs) break; // Nominal time between retries, lest we busy-loop. getNewChild could also wait, so don't double that here. @@ -1327,25 +1328,38 @@ bool DocumentBroker::autoSave(const bool force, const bool dontSaveIfUnmodified) } else if (isModified()) { + // The configured maximum idle duration before saving. Zero to disable. + static const std::chrono::milliseconds MaxIdleSaveDurationMs = std::chrono::seconds( + LOOLWSD::getConfigValue<int>("per_document.idlesave_duration_secs", 30)); + + // The configured maximum duration before saving. Zero to disable. + static const std::chrono::milliseconds MaxAutoSaveDurationMs = std::chrono::seconds( + LOOLWSD::getConfigValue<int>("per_document.autosave_duration_secs", 300)); + const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); - const std::chrono::milliseconds::rep inactivityTimeMs = std::chrono::duration_cast<std::chrono::milliseconds>(now - _lastActivityTime).count(); - const std::chrono::milliseconds::rep timeSinceLastSaveMs = std::chrono::duration_cast<std::chrono::milliseconds>(now - _lastSaveTime).count(); - LOG_TRC("Time since last save of docKey [" << _docKey << "] is " << timeSinceLastSaveMs << - "ms and most recent activity was " << inactivityTimeMs << "ms ago."); + const std::chrono::milliseconds inactivityTimeMs + = std::chrono::duration_cast<std::chrono::milliseconds>(now - _lastActivityTime); + const std::chrono::milliseconds timeSinceLastSaveMs + = std::chrono::duration_cast<std::chrono::milliseconds>(now - _lastSaveTime); + LOG_TRC("Time since last save of docKey [" + << _docKey << "] is " << timeSinceLastSaveMs.count() + << " ms and most recent activity was " << inactivityTimeMs.count() << " ms ago."); - static const int idleSaveDurationMs = LOOLWSD::getConfigValue<int>("per_document.idlesave_duration_secs", 30) * 1000; - static const int autoSaveDurationMs = LOOLWSD::getConfigValue<int>("per_document.autosave_duration_secs", 300) * 1000; bool save = false; // Zero or negative config value disables save. // Either we've been idle long enough, or it's auto-save time. - if (idleSaveDurationMs > 0 && inactivityTimeMs >= idleSaveDurationMs) + if (MaxIdleSaveDurationMs > std::chrono::milliseconds::zero() + && inactivityTimeMs >= MaxIdleSaveDurationMs) { save = true; } - if (autoSaveDurationMs > 0 && timeSinceLastSaveMs >= autoSaveDurationMs) + + if (MaxAutoSaveDurationMs > std::chrono::milliseconds::zero() + && timeSinceLastSaveMs >= MaxAutoSaveDurationMs) { save = true; } + if (save) { LOG_TRC("Sending timed save command for [" << _docKey << "]."); |