From 52f2720af102c9a4800db085bbe09e60e5d6a3c7 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Tue, 6 Feb 2024 18:05:09 +0000 Subject: lok: implement a joinThreads function - to wind down thread pools. Necessary to do this before forking on Unix systems; use a dynamic_cast interface since this is all for internal use. Change-Id: I8a911322acd4ec5654eb0d14804c09d513a0bd4b Signed-off-by: Michael Meeks Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163335 Tested-by: Jenkins --- include/LibreOfficeKit/LibreOfficeKit.h | 3 +++ include/LibreOfficeKit/LibreOfficeKit.hxx | 12 +++++++++++- include/comphelper/lok.hxx | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 963d7962a6c2..78651128d3ac 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -140,6 +140,9 @@ struct _LibreOfficeKitClass /// @see lok::Office::stopURP void (*stopURP)(LibreOfficeKit* pThis, void* pSendURPToLOContext); + + /// @see lok::Office::joinThreads + int (*joinThreads)(LibreOfficeKit* pThis); }; #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 29e644900caf..e94053378355 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -1051,7 +1051,6 @@ public: * @since LibreOffice 6.0 * @param pURL macro url to run */ - bool runMacro( const char* pURL) { return mpThis->pClass->runMacro( mpThis, pURL ); @@ -1197,6 +1196,17 @@ public: { mpThis->pClass->stopURP(mpThis, pURPContext); } + + /** + * Joins all threads if possible to get down to a single process + * which can be forked from safely. + * + * @returns non-zero for successful join, 0 for failure. + */ + int joinThreads() + { + return mpThis->pClass->joinThreads(mpThis); + } }; /// Factory method to create a lok::Office instance. diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx index 545136f762ea..4ca03f049225 100644 --- a/include/comphelper/lok.hxx +++ b/include/comphelper/lok.hxx @@ -20,6 +20,14 @@ class LanguageTag; namespace comphelper::LibreOfficeKit { +/// interface for allowing threads to be transiently shutdown. +class COMPHELPER_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") ThreadJoinable +{ +public: + /// shutdown and join threads, @returns true on success + virtual bool joinThreads() = 0; +}; + // Functions to be called only from the LibreOfficeKit implementation in desktop, not from other // places in LibreOffice code. -- cgit