desktop/source/lib/init.cxx | 50 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-)
New commits: commit b5f44b5f68dcb814771a6eec29ed92fdb56d93d2 Author: Caolán McNamara <[email protected]> AuthorDate: Wed May 21 17:53:20 2025 +0100 Commit: Michael Meeks <[email protected]> CommitDate: Thu May 22 00:03:04 2025 +0200 join restartable threads on large trimMemory effort Change-Id: Ibbb1471fb1436e7894cdc6946410a88e52dd50c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185627 Reviewed-by: Michael Meeks <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 058c8d5397fa..a51f0e8d2704 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3339,6 +3339,18 @@ static char* lo_extractDocumentStructureRequest(LibreOfficeKit* /*pThis*/, const return strdup("{ }"); } +namespace { + +enum class JoinThreads +{ + ALL, + RESTARTS_ON_DEMAND +}; + +} + +static int joinThreads(JoinThreads eCategory); + static void lo_trimMemory(LibreOfficeKit* /* pThis */, int nTarget) { vcl::lok::trimMemory(nTarget); @@ -3371,6 +3383,10 @@ static void lo_trimMemory(LibreOfficeKit* /* pThis */, int nTarget) } } } + + // When more agressively reclaiming memory then shutdown threads which + // will restart on demand. + joinThreads(JoinThreads::RESTARTS_ON_DEMAND); } if (nTarget > 1000) @@ -3548,8 +3564,7 @@ static void lo_stopURP(LibreOfficeKit* /* pThis */, static_cast<FunctionBasedURPConnection*>(pFunctionBasedURPConnection)->close(); } - -static int lo_joinThreads(LibreOfficeKit* /* pThis */) +static int joinThreads(JoinThreads eCategory) { comphelper::ThreadPool &pool = comphelper::ThreadPool::getSharedOptimalPool(); if (!pool.joinThreadsIfIdle()) @@ -3563,17 +3578,20 @@ static int lo_joinThreads(LibreOfficeKit* /* pThis */) if (joinable && !joinable->joinThreads()) return 0; - auto ucpWebdav = xContext->getServiceManager()->createInstanceWithContext( - "com.sun.star.ucb.WebDAVManager", xContext); - joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(ucpWebdav.get()); - if (joinable && !joinable->joinThreads()) - return 0; + if (eCategory == JoinThreads::ALL) + { + auto ucpWebdav = xContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.ucb.WebDAVManager", xContext); + joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(ucpWebdav.get()); + if (joinable && !joinable->joinThreads()) + return 0; - auto progressThread = xContext->getServiceManager()->createInstanceWithContext( - "com.sun.star.task.StatusIndicatorFactory", xContext); - joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(progressThread.get()); - if (joinable && !joinable->joinThreads()) - return 0; + auto progressThread = xContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.task.StatusIndicatorFactory", xContext); + joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(progressThread.get()); + if (joinable && !joinable->joinThreads()) + return 0; + } // Ensure configmgr's write thread is down css::uno::Reference< css::util::XFlushable >( @@ -3581,11 +3599,17 @@ static int lo_joinThreads(LibreOfficeKit* /* pThis */) comphelper::getProcessComponentContext()), css::uno::UNO_QUERY_THROW)->flush(); - salhelper::Timer::joinThread(); + if (eCategory == JoinThreads::ALL) + salhelper::Timer::joinThread(); return 1; } +static int lo_joinThreads(LibreOfficeKit* /* pThis */) +{ + return joinThreads(JoinThreads::ALL); +} + static void lo_startThreads(LibreOfficeKit* /* pThis */) { salhelper::Timer::startThread();
