[Libreoffice-commits] core.git: comphelper/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 17 15:06:10 UTC 2019


 comphelper/source/processfactory/processfactory.cxx |   38 +++++++++++++-------
 1 file changed, 25 insertions(+), 13 deletions(-)

New commits:
commit 884ad0d1af88f9985d30ef0dfe92d89e82f8e576
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Apr 17 14:29:18 2019 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Apr 17 17:00:56 2019 +0200

    Split localProcessFactory function into class with setter and getter
    
    ...which avoids a false positive from an upcoming loplugin that finds suspicious
    uses of variables during their own initialization (as happened with xReturn in
    getProcessServiceFactory).
    
    Change-Id: I40e90e2e74cde84a3425b014d87584f4a56c0e22
    Reviewed-on: https://gerrit.libreoffice.org/70877
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/comphelper/source/processfactory/processfactory.cxx b/comphelper/source/processfactory/processfactory.cxx
index 720ec6e0fb67..31a2e7adfe05 100644
--- a/comphelper/source/processfactory/processfactory.cxx
+++ b/comphelper/source/processfactory/processfactory.cxx
@@ -33,32 +33,44 @@ using namespace osl;
 namespace comphelper
 {
 
-/*
-    This function preserves only that the xProcessFactory variable will not be create when
-    the library is loaded.
-*/
-static Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, bool bSet )
-{
-    Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
+namespace {
 
-    static Reference< XMultiServiceFactory > xProcessFactory;
-    if ( bSet )
+class LocalProcessFactory {
+public:
+    void set( const Reference< XMultiServiceFactory >& xSMgr )
     {
+        Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
+
         xProcessFactory = xSMgr;
     }
 
-    return xProcessFactory;
-}
+    Reference< XMultiServiceFactory > get()
+    {
+        Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
 
+        return xProcessFactory;
+    }
+
+private:
+    Reference< XMultiServiceFactory > xProcessFactory;
+};
+
+/*
+    This var preserves only that the above xProcessFactory variable will not be create when
+    the library is loaded.
+*/
+LocalProcessFactory localProcessFactory;
+
+}
 
 void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
 {
-    localProcessFactory( xSMgr, true );
+    localProcessFactory.set( xSMgr );
 }
 
 Reference< XMultiServiceFactory > getProcessServiceFactory()
 {
-    Reference< XMultiServiceFactory> xReturn = localProcessFactory( xReturn, false );
+    Reference< XMultiServiceFactory> xReturn = localProcessFactory.get();
     if ( !xReturn.is() )
     {
         throw DeploymentException( "null process service factory" );


More information about the Libreoffice-commits mailing list