diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2024-02-06 18:05:09 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2024-02-14 18:27:16 +0100 |
commit | 269a307da6bc4f8f4c759662703e20d4b6860f9a (patch) | |
tree | 2e8204022f6c36dab4bb49fdab748661024d9d6d /desktop | |
parent | 1d30e8bbb945c73aaf4114d927683990b3331dc8 (diff) |
lok: implement a joinThreads function - to wind down thread pools.
cp-24.04.0-1
Necessary to do this before forking on Unix systems; use a
dynamic_cast interface since this is all for internal use.
Change-Id: I8a911322acd4ec5654eb0d14804c09d513a0bd4b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163210
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index d9809cf56ce3..c9f276a67eeb 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3593,10 +3593,11 @@ void DesktopLOKTest::testABI() CPPUNIT_ASSERT_EQUAL(classOffset(17), offsetof(struct _LibreOfficeKitClass, trimMemory)); CPPUNIT_ASSERT_EQUAL(classOffset(18), offsetof(struct _LibreOfficeKitClass, startURP)); CPPUNIT_ASSERT_EQUAL(classOffset(19), offsetof(struct _LibreOfficeKitClass, stopURP)); + CPPUNIT_ASSERT_EQUAL(classOffset(20), offsetof(struct _LibreOfficeKitClass, joinThreads)); // When extending LibreOfficeKit with a new function pointer, add new assert for the offsetof the // new function pointer and bump this assert for the size of the class. - CPPUNIT_ASSERT_EQUAL(classOffset(20), sizeof(struct _LibreOfficeKitClass)); + CPPUNIT_ASSERT_EQUAL(classOffset(21), sizeof(struct _LibreOfficeKitClass)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(0), offsetof(struct _LibreOfficeKitDocumentClass, destroy)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(1), offsetof(struct _LibreOfficeKitDocumentClass, saveAs)); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 0fd3e62a571c..3b97df3faa1c 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2581,6 +2581,8 @@ lo_startURP(LibreOfficeKit* pThis, void* pReceiveURPFromLOContext, void* pSendUR static void lo_stopURP(LibreOfficeKit* pThis, void* pSendURPToLOContext); +static int lo_joinThreads(LibreOfficeKit* pThis); + static void lo_runLoop(LibreOfficeKit* pThis, LibreOfficeKitPollCallback pPollCallback, LibreOfficeKitWakeCallback pWakeCallback, @@ -2625,6 +2627,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl() m_pOfficeClass->trimMemory = lo_trimMemory; m_pOfficeClass->startURP = lo_startURP; m_pOfficeClass->stopURP = lo_stopURP; + m_pOfficeClass->joinThreads = lo_joinThreads; gOfficeClass = m_pOfficeClass; } @@ -3357,6 +3360,26 @@ static void lo_stopURP(LibreOfficeKit* /* pThis */, static_cast<FunctionBasedURPConnection*>(pFunctionBasedURPConnection)->close(); } + +static int lo_joinThreads(LibreOfficeKit* /* pThis */) +{ + comphelper::ThreadPool &pool = comphelper::ThreadPool::getSharedOptimalPool(); + pool.joinThreadsIfIdle(); + +// if (comphelper::getWorkerCount() > 0) +// return 0; + + // Grammar checker thread + css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv = + css::linguistic2::LinguServiceManager::create(xContext); + + auto joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(xLangSrv.get()); + if (joinable && !joinable->joinThreads()) + return 0; + + return 1; +} + static void lo_registerCallback (LibreOfficeKit* pThis, LibreOfficeKitCallback pCallback, void* pData) |