wsd/LOOLWSD.cpp | 70 +++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 36 deletions(-)
New commits: commit 228eb98f4c757288e011a4af5dc6bc1d4770be5c Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Jan 1 18:25:19 2017 -0500 wsd: move rebalanceChildren and avoid declaration Change-Id: Ie8e7e1e28f5496cf5376622cb8f24696e45cb5fc Reviewed-on: https://gerrit.libreoffice.org/32628 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 0268407..f8e2c3c 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -353,7 +353,40 @@ static bool cleanupChildren() return removed; } -static bool rebalanceChildren(int balance, const bool force); +/// Decides how many children need spawning and spanws. +/// When force is true, no check of elapsed time since last request is done. +/// Returns true only if at least one child was requested to spawn. +static bool rebalanceChildren(int balance, const bool force) +{ + Util::assertIsLocked(DocBrokersMutex); + Util::assertIsLocked(NewChildrenMutex); + + // Do the cleanup first. + const bool rebalance = cleanupChildren(); + + const auto duration = (std::chrono::steady_clock::now() - LastForkRequestTime); + const auto durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); + if (durationMs >= CHILD_TIMEOUT_MS) + { + // Children taking too long to spawn. + // Forget we had requested any, and request anew. + OutstandingForks = 0; + } + + const auto available = NewChildren.size(); + balance -= available; + balance -= OutstandingForks; + + if (balance > 0 && (force || rebalance || durationMs >= CHILD_TIMEOUT_MS)) + { + LOG_DBG("prespawnChildren: Have " << available << " spare " << + (available == 1 ? "child" : "children") << + ", forking " << balance << " more."); + return forkChildren(balance); + } + + return false; +} /// Called on startup only. static void preForkChildren() @@ -392,41 +425,6 @@ static bool prespawnChildren(const bool force) return rebalanceChildren(numPreSpawn, force); } -/// Decides how many children need spawning and spanws. -/// When force is true, no check of elapsed time since last request is done. -/// Returns true only if at least one child was requested to spawn. -static bool rebalanceChildren(int balance, const bool force) -{ - Util::assertIsLocked(DocBrokersMutex); - Util::assertIsLocked(NewChildrenMutex); - - // Do the cleanup first. - const bool rebalance = cleanupChildren(); - - const auto duration = (std::chrono::steady_clock::now() - LastForkRequestTime); - const auto durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); - if (durationMs >= CHILD_TIMEOUT_MS) - { - // Children taking too long to spawn. - // Forget we had requested any, and request anew. - OutstandingForks = 0; - } - - const auto available = NewChildren.size(); - balance -= available; - balance -= OutstandingForks; - - if (balance > 0 && (force || rebalance || durationMs >= CHILD_TIMEOUT_MS)) - { - LOG_DBG("prespawnChildren: Have " << available << " spare " << - (available == 1 ? "child" : "children") << - ", forking " << balance << " more."); - return forkChildren(balance); - } - - return false; -} - static size_t addNewChild(const std::shared_ptr<ChildProcess>& child) { std::unique_lock<std::mutex> lock(NewChildrenMutex); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits