framework/qa/cppunit/dispatchtest.cxx |    9 +++++++++
 1 file changed, 9 insertions(+)

New commits:
commit 00f73472c1342213b7eb48b9e48175db3c9041c2
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Apr 12 14:00:16 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Apr 13 07:57:16 2023 +0200

    try to fix CppunitTest_framework_dispatch on windows
    
    I see occasional failures here, possibly they are a threading
    issue since we are touching these fields from multiple threads.
    Add a mutex to see if it helps.
    
    Change-Id: I7277e96d07d292a6bc1d333dabec7a82fc607465
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150281
    Tested-by: Noel Grandin <[email protected]>
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/framework/qa/cppunit/dispatchtest.cxx 
b/framework/qa/cppunit/dispatchtest.cxx
index f45f0da5bf0e..fd091f42bd5a 100644
--- a/framework/qa/cppunit/dispatchtest.cxx
+++ b/framework/qa/cppunit/dispatchtest.cxx
@@ -16,6 +16,7 @@
 #include <com/sun/star/util/URLTransformer.hpp>
 
 #include <rtl/ref.hxx>
+#include <mutex>
 
 using namespace ::com::sun::star;
 
@@ -25,6 +26,7 @@ namespace
 class MyInterceptor
     : public cppu::WeakImplHelper<frame::XDispatchProviderInterceptor, 
frame::XInterceptorInfo>
 {
+    std::mutex maMutex;
     uno::Reference<frame::XDispatchProvider> m_xMaster;
     uno::Reference<frame::XDispatchProvider> m_xSlave;
     uno::Sequence<OUString> m_aDisabledCommands;
@@ -67,6 +69,7 @@ MyInterceptor::MyInterceptor()
 
 int MyInterceptor::getExpected()
 {
+    std::unique_lock aGuard(maMutex);
     int nRet = m_nExpected;
     m_nExpected = 0;
     return nRet;
@@ -74,6 +77,7 @@ int MyInterceptor::getExpected()
 
 int MyInterceptor::getUnexpected()
 {
+    std::unique_lock aGuard(maMutex);
     int nRet = m_nUnexpected;
     m_nUnexpected = 0;
     return nRet;
@@ -84,22 +88,26 @@ uno::Sequence<OUString> MyInterceptor::getInterceptedURLs() 
{ return m_aDisabled
 void MyInterceptor::setMasterDispatchProvider(
     const uno::Reference<frame::XDispatchProvider>& xNewSupplier)
 {
+    std::unique_lock aGuard(maMutex);
     m_xMaster = xNewSupplier;
 }
 
 uno::Reference<frame::XDispatchProvider> 
MyInterceptor::getMasterDispatchProvider()
 {
+    std::unique_lock aGuard(maMutex);
     return m_xMaster;
 }
 
 void MyInterceptor::setSlaveDispatchProvider(
     const uno::Reference<frame::XDispatchProvider>& xNewSupplier)
 {
+    std::unique_lock aGuard(maMutex);
     m_xSlave = xNewSupplier;
 }
 
 uno::Reference<frame::XDispatchProvider> 
MyInterceptor::getSlaveDispatchProvider()
 {
+    std::unique_lock aGuard(maMutex);
     return m_xSlave;
 }
 
@@ -122,6 +130,7 @@ uno::Reference<frame::XDispatch> 
MyInterceptor::queryDispatch(const util::URL& r
                                                               const OUString& 
/*rTargetFrameName*/,
                                                               sal_Int32 
/*SearchFlags*/)
 {
+    std::unique_lock aGuard(maMutex);
     if (std::find(std::cbegin(m_aDisabledCommands), 
std::cend(m_aDisabledCommands), rURL.Complete)
         != std::cend(m_aDisabledCommands))
         ++m_nExpected;

Reply via email to