comphelper/source/misc/lok.cxx | 12 ++++++++++++ desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 ++- desktop/source/lib/init.cxx | 8 ++++++++ include/LibreOfficeKit/LibreOfficeKit.h | 3 +++ include/LibreOfficeKit/LibreOfficeKit.hxx | 9 +++++++++ include/comphelper/lok.hxx | 6 ++++++ 6 files changed, 40 insertions(+), 1 deletion(-)
New commits: commit 9dab5edb90d14ad6f71cc2ac96cc504c1e8c290b Author: Michael Meeks <[email protected]> AuthorDate: Wed Mar 27 17:25:24 2024 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Mar 28 12:29:41 2024 +0100 lok: add isForkedChild method. This can be used to tag short-lived transient 'save' processes to encourage them not to mutate eg. filesystem state that is shared with the parent process. Change-Id: I027d18cbe4ce519b31c4fc1d3ac46b916d1efc87 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165407 Tested-by: Jenkins CollaboraOffice <[email protected]> Tested-by: Caolán McNamara <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index b5cbcc74cb54..c042b0c626e5 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -19,6 +19,8 @@ namespace comphelper::LibreOfficeKit static bool g_bActive(false); +static bool g_bForkedChild(false); + static bool g_bPartInInvalidation(false); static bool g_bTiledPainting(false); @@ -98,6 +100,16 @@ bool isActive() return g_bActive; } +void setForkedChild(bool bIsChild) +{ + g_bForkedChild = bIsChild; +} + +bool isForkedChild() +{ + return g_bForkedChild; +} + void setPartInInvalidation(bool bPartInInvalidation) { g_bPartInInvalidation = bPartInInvalidation; diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 1a0c2fed27b1..298e5a5d7a9b 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3594,10 +3594,11 @@ void DesktopLOKTest::testABI() 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)); + CPPUNIT_ASSERT_EQUAL(classOffset(21), offsetof(struct _LibreOfficeKitClass, setForkedChild)); // 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(21), sizeof(struct _LibreOfficeKitClass)); + CPPUNIT_ASSERT_EQUAL(classOffset(22), 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 437c904e0db2..52882a4a9f88 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2548,6 +2548,8 @@ static void lo_stopURP(LibreOfficeKit* pThis, void* pSendURPToLOContext); static int lo_joinThreads(LibreOfficeKit* pThis); +static void lo_setForkedChild(LibreOfficeKit* pThis, bool bIsChild); + static void lo_runLoop(LibreOfficeKit* pThis, LibreOfficeKitPollCallback pPollCallback, LibreOfficeKitWakeCallback pWakeCallback, @@ -2593,6 +2595,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl() m_pOfficeClass->startURP = lo_startURP; m_pOfficeClass->stopURP = lo_stopURP; m_pOfficeClass->joinThreads = lo_joinThreads; + m_pOfficeClass->setForkedChild = lo_setForkedChild; gOfficeClass = m_pOfficeClass; } @@ -3345,6 +3348,11 @@ static int lo_joinThreads(LibreOfficeKit* /* pThis */) return 1; } +static void lo_setForkedChild(LibreOfficeKit* /* pThis */, bool bIsChild) +{ + comphelper::LibreOfficeKit::setForkedChild(bIsChild); +} + static void lo_registerCallback (LibreOfficeKit* pThis, LibreOfficeKitCallback pCallback, void* pData) diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 450366ccb70c..f57c7ad32843 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -143,6 +143,9 @@ struct _LibreOfficeKitClass /// @see lok::Office::joinThreads int (*joinThreads)(LibreOfficeKit* pThis); + + /// @see lok::Office::setForkedChild + void (*setForkedChild)(LibreOfficeKit* pThis, bool bIsChild); }; #define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize) diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 8b7a211804be..af9ccd12ab2f 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -1222,6 +1222,15 @@ public: { return mpThis->pClass->joinThreads(mpThis); } + + /** + * Informs that this process is either a parent, or a child + * process post-fork, allowing improved resource sharing. + */ + void setForkedChild(bool bIsChild) + { + return mpThis->pClass->setForkedChild(mpThis, bIsChild); + } }; /// Factory method to create a lok::Office instance. diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx index 4ca03f049225..555b749fa6a1 100644 --- a/include/comphelper/lok.hxx +++ b/include/comphelper/lok.hxx @@ -33,6 +33,8 @@ public: COMPHELPER_DLLPUBLIC void setActive(bool bActive = true); +COMPHELPER_DLLPUBLIC void setForkedChild(bool bIsChild = true); + enum class statusIndicatorCallbackType { Start, @@ -49,6 +51,10 @@ COMPHELPER_DLLPUBLIC void setStatusIndicatorCallback( // Check whether the code is running as invoked through LibreOfficeKit. COMPHELPER_DLLPUBLIC bool isActive(); +/// Is this a transient forked child process, that shares many +/// eg. file-system resources with its parent process? +COMPHELPER_DLLPUBLIC bool isForkedChild(); + /// Shift the coordinates before rendering each bitmap. /// Used by Calc to render each tile separately. /// This should be unnecessary (and removed) once Calc
