desktop/source/app/dispatchwatcher.cxx | 18 ++++-------------- desktop/source/app/dispatchwatcher.hxx | 5 ++--- sc/inc/fielduno.hxx | 5 +++-- sc/source/ui/unoobj/fielduno.cxx | 18 ++++++++++-------- 4 files changed, 19 insertions(+), 27 deletions(-)
New commits: commit 7becce20b54973337d9803527fad0b957a56ab31 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 14 10:24:20 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 14 12:35:08 2023 +0000 osl::Mutex->std::mutex in ScHeaderFieldsObj Change-Id: I9e308eee9534297b7257185d6b5f244d4fa86178 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146972 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/inc/fielduno.hxx b/sc/inc/fielduno.hxx index 41a0eb6104f4..fc5ae6d15446 100644 --- a/sc/inc/fielduno.hxx +++ b/sc/inc/fielduno.hxx @@ -32,6 +32,7 @@ #include <com/sun/star/util/XRefreshable.hpp> #include <com/sun/star/util/DateTime.hpp> #include <comphelper/interfacecontainer3.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <comphelper/servicehelper.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/compbase.hxx> @@ -114,9 +115,9 @@ private: std::unique_ptr<ScEditSource> mpEditSource; /// List of refresh listeners. - std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::util::XRefreshListener>> mpRefreshListeners; + std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::util::XRefreshListener>> mpRefreshListeners; /// mutex to lock the InterfaceContainerHelper - osl::Mutex aMutex; + std::mutex aMutex; css::uno::Reference< css::text::XTextField> GetObjectByIndex_Impl(sal_Int32 Index) const; diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index 96271342c06d..afc27560c1fe 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -423,14 +423,15 @@ ScHeaderFieldsObj::~ScHeaderFieldsObj() { mpEditSource.reset(); - // increment refcount to prevent double call off dtor + // increment refcount to prevent double call of dtor osl_atomic_increment( &m_refCount ); + std::unique_lock g(aMutex); if (mpRefreshListeners) { lang::EventObject aEvent; aEvent.Source = static_cast<cppu::OWeakObject*>(this); - mpRefreshListeners->disposeAndClear(aEvent); + mpRefreshListeners->disposeAndClear(g, aEvent); mpRefreshListeners.reset(); } } @@ -533,12 +534,13 @@ void SAL_CALL ScHeaderFieldsObj::removeContainerListener( // XRefreshable void SAL_CALL ScHeaderFieldsObj::refresh( ) { + std::unique_lock g(aMutex); if (mpRefreshListeners) { // Call all listeners. lang::EventObject aEvent; aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); - mpRefreshListeners->notifyEach( &util::XRefreshListener::refreshed, aEvent); + mpRefreshListeners->notifyEach( g, &util::XRefreshListener::refreshed, aEvent); } } @@ -546,10 +548,10 @@ void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util: { if (xListener.is()) { - SolarMutexGuard aGuard; + std::unique_lock g(aMutex); if (!mpRefreshListeners) - mpRefreshListeners.reset(new comphelper::OInterfaceContainerHelper3<util::XRefreshListener>(aMutex)); - mpRefreshListeners->addInterface(xListener); + mpRefreshListeners.reset(new comphelper::OInterfaceContainerHelper4<util::XRefreshListener>()); + mpRefreshListeners->addInterface(g, xListener); } } @@ -557,9 +559,9 @@ void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<uti { if (xListener.is()) { - SolarMutexGuard aGuard; + std::unique_lock g(aMutex); if (mpRefreshListeners) - mpRefreshListeners->removeInterface(xListener); + mpRefreshListeners->removeInterface(g, xListener); } } commit 1f59cbe6f0d879275ddd82dd0eaf224cbd1dec21 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 14 09:39:21 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 14 12:34:58 2023 +0000 osl::Mutex->std::atomic in DispatchWatcher Change-Id: I7cad64f9031dd05e08321110ec670d3c744f03c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146971 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 8ae45b40daa6..5b7fd944fee9 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -398,11 +398,8 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest "unsupported dispatch request <" << aName << ">"); if( xDispatcher.is() ) { - { - osl::MutexGuard aGuard(m_mutex); - // Remember request so we can find it in statusChanged! - m_nRequestCount++; - } + // Remember request so we can find it in statusChanged! + m_nRequestCount++; // Use local vector to store dispatcher because we have to fill our request container before // we can dispatch. Otherwise it would be possible that statusChanged is called before we dispatched all requests!! @@ -770,18 +767,13 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest xDisp->dispatchWithNotification( aDispatche.aURL, aArgs, this ); else { - { - osl::MutexGuard aGuard(m_mutex); - m_nRequestCount--; - } + m_nRequestCount--; xDispatch->dispatch( aDispatche.aURL, aArgs ); } } } - ::osl::ClearableMutexGuard aGuard(m_mutex); bool bEmpty = (m_nRequestCount == 0); - aGuard.clear(); // No more asynchronous requests? // The requests are removed from the request container after they called back to this @@ -809,9 +801,7 @@ void SAL_CALL DispatchWatcher::disposing( const css::lang::EventObject& ) void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) { - osl::ClearableMutexGuard aGuard(m_mutex); - sal_Int16 nCount = --m_nRequestCount; - aGuard.clear(); + int nCount = --m_nRequestCount; RequestHandler::RequestsCompleted(); if ( !nCount && !RequestHandler::AreRequestsPending() ) { diff --git a/desktop/source/app/dispatchwatcher.hxx b/desktop/source/app/dispatchwatcher.hxx index 221cac915af3..70a7fd42e679 100644 --- a/desktop/source/app/dispatchwatcher.hxx +++ b/desktop/source/app/dispatchwatcher.hxx @@ -22,7 +22,7 @@ #include <cppuhelper/implbase.hxx> #include <com/sun/star/frame/XDispatchResultListener.hpp> #include <optional> - +#include <atomic> #include <vector> namespace desktop @@ -77,9 +77,8 @@ class DispatchWatcher : public ::cppu::WeakImplHelper< css::frame::XDispatchResu bool executeDispatchRequests( const std::vector<DispatchRequest>& aDispatches, bool bNoTerminate ); private: - osl::Mutex m_mutex; - sal_Int16 m_nRequestCount; + std::atomic<int> m_nRequestCount; }; }