[Libreoffice-commits] core.git: 8 commits - desktop/source

Stephan Bergmann sbergman at redhat.com
Fri Mar 11 15:42:24 UTC 2016


 desktop/source/app/app.cxx             |    8 +--
 desktop/source/app/dispatchwatcher.cxx |    7 ---
 desktop/source/app/dispatchwatcher.hxx |    7 ---
 desktop/source/app/officeipcthread.cxx |   67 +++++++++++++++------------------
 desktop/source/app/officeipcthread.hxx |   14 +++---
 5 files changed, 45 insertions(+), 58 deletions(-)

New commits:
commit 69bb5e849825e32d9fe929519813ede56ca76997
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 16:10:21 2016 +0100

    Thread safety
    
    Change-Id: I13282ac1d6b3f1323e9056a4160301bd503ac271

diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 5662823..6bf4dc5 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -666,6 +666,7 @@ OfficeIPCThread::~OfficeIPCThread()
 
 void OfficeIPCThread::SetReady()
 {
+    osl::MutexGuard g(GetMutex());
     if (pGlobalOfficeIPCThread.is())
     {
         pGlobalOfficeIPCThread->cReady.set();
@@ -674,7 +675,11 @@ void OfficeIPCThread::SetReady()
 
 void OfficeIPCThread::WaitForReady()
 {
-    rtl::Reference< OfficeIPCThread > const & t(pGlobalOfficeIPCThread);
+    rtl::Reference<OfficeIPCThread> t;
+    {
+        osl::MutexGuard g(GetMutex());
+        t =  pGlobalOfficeIPCThread;
+    }
     if (t.is())
     {
         t->cReady.wait();
@@ -683,6 +688,7 @@ void OfficeIPCThread::WaitForReady()
 
 bool OfficeIPCThread::IsEnabled()
 {
+    osl::MutexGuard g(GetMutex());
     return pGlobalOfficeIPCThread.is();
 }
 
commit 8db7c0de57d3c5129236fc6cfc37e93cfb75e49f
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 16:08:05 2016 +0100

    No need for a complicated arg to SetReady
    
    Change-Id: Iacb900ab7de0f01a78441019d2455abacc974617

diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 6c94f62..5662823 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -638,7 +638,7 @@ void OfficeIPCThread::DisableOfficeIPCThread(bool join)
         // release mutex to avoid deadlocks
         aMutex.clear();
 
-        OfficeIPCThread::SetReady(pOfficeIPCThread);
+        pOfficeIPCThread->cReady.set();
 
         // exit gracefully and join
         if (join)
@@ -664,14 +664,11 @@ OfficeIPCThread::~OfficeIPCThread()
     pGlobalOfficeIPCThread.clear();
 }
 
-void OfficeIPCThread::SetReady(
-    rtl::Reference< OfficeIPCThread > const & pThread)
+void OfficeIPCThread::SetReady()
 {
-    rtl::Reference< OfficeIPCThread > const & t(
-        pThread.is() ? pThread : pGlobalOfficeIPCThread);
-    if (t.is())
+    if (pGlobalOfficeIPCThread.is())
     {
-        t->cReady.set();
+        pGlobalOfficeIPCThread->cReady.set();
     }
 }
 
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 1319d39..919ec44 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -117,9 +117,7 @@ class OfficeIPCThread : public salhelper::Thread
     static Status               EnableOfficeIPCThread();
     static void                 DisableOfficeIPCThread(bool join = true);
     // start dispatching events...
-    static void                 SetReady(
-        rtl::Reference< OfficeIPCThread > const & pThread =
-            rtl::Reference< OfficeIPCThread >());
+    static void                 SetReady();
     static void                 WaitForReady();
     static bool                 IsEnabled();
 
commit 34eb5546a1f8824c275337644d6db1c344e596fc
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 15:47:18 2016 +0100

    Turn static s_bInEnableRequests into an ExecuteCmdLineRequests arg
    
    Change-Id: Idb0b252d986bc866409928f4a126f55608c6347c

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index a7d97de..3166b34 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -2407,7 +2407,7 @@ void Desktop::OpenClients()
         }
 
         // Process request
-        if ( OfficeIPCThread::ExecuteCmdLineRequests( aRequest ) )
+        if ( OfficeIPCThread::ExecuteCmdLineRequests(aRequest, false) )
         {
             // Don't do anything if we have successfully called terminate at desktop:
             return;
@@ -2481,7 +2481,7 @@ void Desktop::OpenDefault()
 
     ProcessDocumentsRequest aRequest(rArgs.getCwdUrl());
     aRequest.aOpenList.push_back(aName);
-    OfficeIPCThread::ExecuteCmdLineRequests( aRequest );
+    OfficeIPCThread::ExecuteCmdLineRequests(aRequest, false);
 }
 
 
@@ -2604,7 +2604,7 @@ void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent )
                 std::vector<OUString> const & data(rAppEvent.GetStringsData());
                 docsRequest.aOpenList.insert(
                     docsRequest.aOpenList.end(), data.begin(), data.end());
-                OfficeIPCThread::ExecuteCmdLineRequests(docsRequest);
+                OfficeIPCThread::ExecuteCmdLineRequests(docsRequest, false);
             }
         }
         break;
@@ -2621,7 +2621,7 @@ void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent )
                 std::vector<OUString> const & data(rAppEvent.GetStringsData());
                 docsRequest.aPrintList.insert(
                     docsRequest.aPrintList.end(), data.begin(), data.end());
-                OfficeIPCThread::ExecuteCmdLineRequests(docsRequest);
+                OfficeIPCThread::ExecuteCmdLineRequests(docsRequest, false);
             }
         }
         break;
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 00d0147..6c94f62 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -296,7 +296,7 @@ IMPL_STATIC_LINK_TYPED( ProcessEventsClass_Impl, ProcessDocumentsEvent, void*, p
 {
     // Documents requests are processed by the OfficeIPCThread implementation
     ProcessDocumentsRequest* pDocsRequest = static_cast<ProcessDocumentsRequest*>(pEvent);
-    OfficeIPCThread::ExecuteCmdLineRequests( *pDocsRequest );
+    OfficeIPCThread::ExecuteCmdLineRequests(*pDocsRequest, false);
     delete pDocsRequest;
 }
 
@@ -394,8 +394,6 @@ void OfficeIPCThread::SetDowning()
         pGlobalOfficeIPCThread->mState = State::Downing;
 }
 
-static bool s_bInEnableRequests = false;
-
 void OfficeIPCThread::EnableRequests()
 {
     // switch between just queueing the requests and executing them
@@ -403,15 +401,13 @@ void OfficeIPCThread::EnableRequests()
 
     if ( pGlobalOfficeIPCThread.is() )
     {
-        s_bInEnableRequests = true;
         if (pGlobalOfficeIPCThread->mState != State::Downing) {
             pGlobalOfficeIPCThread->mState = State::RequestsEnabled;
         }
         // hit the compiler over the head
         ProcessDocumentsRequest aEmptyReq = ProcessDocumentsRequest( boost::optional< OUString >() );
         // trigger already queued requests
-        OfficeIPCThread::ExecuteCmdLineRequests( aEmptyReq );
-        s_bInEnableRequests = false;
+        OfficeIPCThread::ExecuteCmdLineRequests(aEmptyReq, true);
     }
 }
 
@@ -1047,7 +1043,8 @@ static void AddConversionsToDispatchList(
 }
 
 
-bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest )
+bool OfficeIPCThread::ExecuteCmdLineRequests(
+    ProcessDocumentsRequest& aRequest, bool noTerminate)
 {
     // protect the dispatch list
     osl::ClearableMutexGuard aGuard( GetMutex() );
@@ -1084,7 +1081,7 @@ bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest
         aGuard.clear();
 
         // Execute dispatch requests
-        bShutdown = pGlobalOfficeIPCThread->mpDispatchWatcher->executeDispatchRequests( aTempList, s_bInEnableRequests );
+        bShutdown = pGlobalOfficeIPCThread->mpDispatchWatcher->executeDispatchRequests( aTempList, noTerminate);
 
         // set processed flag
         if (aRequest.pcProcessed != nullptr)
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 13af937..1319d39 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -110,7 +110,8 @@ class OfficeIPCThread : public salhelper::Thread
     static void                 EnableRequests();
     static bool                 AreRequestsPending();
     static void                 RequestsCompleted();
-    static bool                 ExecuteCmdLineRequests( ProcessDocumentsRequest& );
+    static bool                 ExecuteCmdLineRequests(
+        ProcessDocumentsRequest&, bool noTerminate);
 
     // return sal_False if second office
     static Status               EnableOfficeIPCThread();
commit ee31139b64eb9517619578bb02b3261b85d635ae
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 15:34:01 2016 +0100

    Combine mbDowning, mbRequestsEnabled as mState
    
    Change-Id: I3110f1690f0d7b0f19e7576f02cb1159342881a1

diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 6c41f12..00d0147 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -391,7 +391,7 @@ void OfficeIPCThread::SetDowning()
     ::osl::MutexGuard   aGuard( GetMutex() );
 
     if ( pGlobalOfficeIPCThread.is() )
-        pGlobalOfficeIPCThread->mbDowning = true;
+        pGlobalOfficeIPCThread->mState = State::Downing;
 }
 
 static bool s_bInEnableRequests = false;
@@ -404,7 +404,9 @@ void OfficeIPCThread::EnableRequests()
     if ( pGlobalOfficeIPCThread.is() )
     {
         s_bInEnableRequests = true;
-        pGlobalOfficeIPCThread->mbRequestsEnabled = true;
+        if (pGlobalOfficeIPCThread->mState != State::Downing) {
+            pGlobalOfficeIPCThread->mState = State::RequestsEnabled;
+        }
         // hit the compiler over the head
         ProcessDocumentsRequest aEmptyReq = ProcessDocumentsRequest( boost::optional< OUString >() );
         // trigger already queued requests
@@ -634,7 +636,7 @@ void OfficeIPCThread::DisableOfficeIPCThread(bool join)
             pGlobalOfficeIPCThread);
         pGlobalOfficeIPCThread.clear();
 
-        pOfficeIPCThread->mbDowning = true;
+        pOfficeIPCThread->mState = State::Downing;
         pOfficeIPCThread->maPipe.close();
 
         // release mutex to avoid deadlocks
@@ -652,8 +654,7 @@ void OfficeIPCThread::DisableOfficeIPCThread(bool join)
 
 OfficeIPCThread::OfficeIPCThread() :
     Thread( "OfficeIPCThread" ),
-    mbDowning( false ),
-    mbRequestsEnabled( false ),
+    mState( State::Starting ),
     mnPendingRequests( 0 )
 {
 }
@@ -722,7 +723,7 @@ void OfficeIPCThread::execute()
             // down during wait
             osl::ClearableMutexGuard aGuard( GetMutex() );
 
-            if ( mbDowning )
+            if ( mState == State::Downing )
             {
                 break;
             }
@@ -963,7 +964,7 @@ void OfficeIPCThread::execute()
         {
             {
                 osl::MutexGuard aGuard( GetMutex() );
-                if ( mbDowning )
+                if ( mState == State::Downing )
                 {
                     break;
                 }
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index b8770c6..13af937 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -72,9 +72,10 @@ class OfficeIPCThread : public salhelper::Thread
   private:
     static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread;
 
+    enum class State { Starting, RequestsEnabled, Downing };
+
     osl::Pipe                   maPipe;
-    bool                        mbDowning;
-    bool                        mbRequestsEnabled;
+    State                       mState;
     int                         mnPendingRequests;
     rtl::Reference<DispatchWatcher> mpDispatchWatcher;
 
@@ -121,7 +122,7 @@ class OfficeIPCThread : public salhelper::Thread
     static void                 WaitForReady();
     static bool                 IsEnabled();
 
-    bool                        AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
+    bool                        AreRequestsEnabled() const { return mState == State::RequestsEnabled; }
 };
 
 
commit f3caa92527aee3c95960e95c90e1e1cdd33f1342
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 15:22:14 2016 +0100

    pDocsRequest cannot be null
    
    Change-Id: I399175f154e0a75779b90b74396c13fe2acbca49

diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index ccc72ec..6c41f12 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -296,12 +296,8 @@ IMPL_STATIC_LINK_TYPED( ProcessEventsClass_Impl, ProcessDocumentsEvent, void*, p
 {
     // Documents requests are processed by the OfficeIPCThread implementation
     ProcessDocumentsRequest* pDocsRequest = static_cast<ProcessDocumentsRequest*>(pEvent);
-
-    if ( pDocsRequest )
-    {
-        OfficeIPCThread::ExecuteCmdLineRequests( *pDocsRequest );
-        delete pDocsRequest;
-    }
+    OfficeIPCThread::ExecuteCmdLineRequests( *pDocsRequest );
+    delete pDocsRequest;
 }
 
 void ImplPostForeignAppEvent( ApplicationEvent* pEvent )
commit 1290a4082c298eecd597a7f268b6a19e1e64e9b8
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 15:05:55 2016 +0100

    Create DispatchRequest via list-initialization
    
    Change-Id: Ic1fc17b028281e64290c6c1d25bbd94fbf27251d

diff --git a/desktop/source/app/dispatchwatcher.hxx b/desktop/source/app/dispatchwatcher.hxx
index 087d338..f78db4f 100644
--- a/desktop/source/app/dispatchwatcher.hxx
+++ b/desktop/source/app/dispatchwatcher.hxx
@@ -58,9 +58,6 @@ class DispatchWatcher : public ::cppu::WeakImplHelper< css::frame::XDispatchResu
 
         struct DispatchRequest
         {
-            DispatchRequest( RequestType aType, const OUString& aFile, boost::optional< OUString > const & cwdUrl, const OUString& aPrinter, const OUString& aFact ) :
-                aRequestType( aType ), aURL( aFile ), aCwdUrl( cwdUrl ), aPrinterName( aPrinter ), aPreselectedFactory( aFact ) {}
-
             RequestType     aRequestType;
             OUString   aURL;
             boost::optional< OUString > aCwdUrl;
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 9260840..ccc72ec 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -996,8 +996,7 @@ static void AddToDispatchList(
     for (std::vector< OUString >::const_iterator i(aRequestList.begin());
          i != aRequestList.end(); ++i)
     {
-        rDispatchList.push_back(
-            DispatchWatcher::DispatchRequest( nType, *i, cwdUrl, aParam, aFactory ));
+        rDispatchList.push_back({nType, *i, cwdUrl, aParam, aFactory});
     }
 }
 
@@ -1046,8 +1045,7 @@ static void AddConversionsToDispatchList(
     for (std::vector< OUString >::const_iterator i(rRequestList.begin());
          i != rRequestList.end(); ++i)
     {
-        rDispatchList.push_back(
-            DispatchWatcher::DispatchRequest( nType, *i, cwdUrl, aParam, rFactory ));
+        rDispatchList.push_back({nType, *i, cwdUrl, aParam, rFactory});
     }
 }
 
commit 2cc88911db9cf81e09270a49c0ee7a13600aa3ab
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 15:01:23 2016 +0100

    Resolve trivial DispatchList typedef
    
    Change-Id: I5a304701aed843f6cdbffcdcf6e04255453f0f48

diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx
index 63e08c7..1952e59 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -180,7 +180,7 @@ DispatchWatcher::~DispatchWatcher()
 }
 
 
-bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequestsList, bool bNoTerminate )
+bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest>& aDispatchRequestsList, bool bNoTerminate )
 {
     Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( ::comphelper::getProcessComponentContext() );
 
diff --git a/desktop/source/app/dispatchwatcher.hxx b/desktop/source/app/dispatchwatcher.hxx
index a71c54b..087d338 100644
--- a/desktop/source/app/dispatchwatcher.hxx
+++ b/desktop/source/app/dispatchwatcher.hxx
@@ -68,8 +68,6 @@ class DispatchWatcher : public ::cppu::WeakImplHelper< css::frame::XDispatchResu
             OUString   aPreselectedFactory;
         };
 
-        typedef std::vector< DispatchRequest > DispatchList;
-
         DispatchWatcher();
 
         virtual ~DispatchWatcher();
@@ -82,7 +80,7 @@ class DispatchWatcher : public ::cppu::WeakImplHelper< css::frame::XDispatchResu
         virtual void SAL_CALL dispatchFinished( const css::frame::DispatchResultEvent& aEvent ) throw( css::uno::RuntimeException, std::exception ) override;
 
         // execute new dispatch request
-        bool executeDispatchRequests( const DispatchList& aDispatches, bool bNoTerminate = false );
+        bool executeDispatchRequests( const std::vector<DispatchRequest>& aDispatches, bool bNoTerminate = false );
 
     private:
         osl::Mutex m_mutex;
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 7d1ebf4..9260840 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -986,7 +986,7 @@ void OfficeIPCThread::execute()
 }
 
 static void AddToDispatchList(
-    DispatchWatcher::DispatchList& rDispatchList,
+    std::vector<DispatchWatcher::DispatchRequest>& rDispatchList,
     boost::optional< OUString > const & cwdUrl,
     std::vector< OUString > const & aRequestList,
     DispatchWatcher::RequestType nType,
@@ -1002,7 +1002,7 @@ static void AddToDispatchList(
 }
 
 static void AddConversionsToDispatchList(
-    DispatchWatcher::DispatchList& rDispatchList,
+    std::vector<DispatchWatcher::DispatchRequest>& rDispatchList,
     boost::optional< OUString > const & cwdUrl,
     std::vector< OUString > const & rRequestList,
     const OUString& rParam,
@@ -1057,7 +1057,7 @@ bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest
     // protect the dispatch list
     osl::ClearableMutexGuard aGuard( GetMutex() );
 
-    static DispatchWatcher::DispatchList    aDispatchList;
+    static std::vector<DispatchWatcher::DispatchRequest> aDispatchList;
 
     // Create dispatch list for dispatch watcher
     AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aInFilter, DispatchWatcher::REQUEST_INFILTER, "", aRequest.aModule );
@@ -1083,7 +1083,7 @@ bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest
         }
 
         // copy for execute
-        DispatchWatcher::DispatchList aTempList( aDispatchList );
+        std::vector<DispatchWatcher::DispatchRequest> aTempList( aDispatchList );
         aDispatchList.clear();
 
         aGuard.clear();
commit 9095c5495b0760aef4bd0a4f9539e2178a11063a
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Mar 11 14:57:33 2016 +0100

    Use range-based for loop
    
    Change-Id: Icf9dd7ffdc39ff64e9eac11050c8bfbfef6f004d

diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx
index 35864f1..63e08c7 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -184,16 +184,13 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
 {
     Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( ::comphelper::getProcessComponentContext() );
 
-    DispatchList::const_iterator    p;
     std::vector< DispatchHolder >   aDispatches;
     OUString                 aAsTemplateArg( "AsTemplate" );
     bool                     bSetInputFilter = false;
     OUString                 aForcedInputFilter;
 
-    for ( p = aDispatchRequestsList.begin(); p != aDispatchRequestsList.end(); ++p )
+    for (auto const & aDispatchRequest: aDispatchRequestsList)
     {
-        const DispatchRequest&  aDispatchRequest = *p;
-
         // create parameter array
         sal_Int32 nCount = 4;
         if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )


More information about the Libreoffice-commits mailing list