sfx2/source/inc/eventsupplier.hxx | 3 - sfx2/source/notify/eventsupplier.cxx | 92 +++++++++++++++++------------------ 2 files changed, 49 insertions(+), 46 deletions(-)
New commits: commit f3d795aca9aecb0911771c26fc41bb46a2039b22 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Mon Dec 20 20:17:19 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jan 4 07:06:03 2022 +0100 osl::Mutex->std::mutex in SfxEvents_Impl Change-Id: If154764b5bd9917b1d41b885dc1f4da6812607d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127903 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sfx2/source/inc/eventsupplier.hxx b/sfx2/source/inc/eventsupplier.hxx index 0bbd11ef1773..0a6c1a971daf 100644 --- a/sfx2/source/inc/eventsupplier.hxx +++ b/sfx2/source/inc/eventsupplier.hxx @@ -29,6 +29,7 @@ #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Type.hxx> #include <cppuhelper/implbase.hxx> +#include <mutex> #include <vector> namespace comphelper @@ -45,7 +46,7 @@ class SfxEvents_Impl final : public ::cppu::WeakImplHelper< css::container::XNam css::uno::Sequence< OUString > maEventNames; std::vector< css::uno::Any > maEventData; css::uno::Reference< css::document::XDocumentEventBroadcaster > mxBroadcaster; - ::osl::Mutex maMutex; + std::mutex maMutex; SfxObjectShell *mpObjShell; public: diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx index 08699ca70185..7ac2fd7d830d 100644 --- a/sfx2/source/notify/eventsupplier.cxx +++ b/sfx2/source/notify/eventsupplier.cxx @@ -56,52 +56,54 @@ using namespace ::com::sun::star; void SAL_CALL SfxEvents_Impl::replaceByName( const OUString & aName, const uno::Any & rElement ) { - ::osl::MutexGuard aGuard( maMutex ); + std::unique_lock aGuard( maMutex ); // find the event in the list and replace the data auto nIndex = comphelper::findValue(maEventNames, aName); - if (nIndex != -1) + if (nIndex == -1) + throw container::NoSuchElementException(); + + // check for correct type of the element + if ( !::comphelper::NamedValueCollection::canExtractFrom( rElement ) ) + throw lang::IllegalArgumentException(); + ::comphelper::NamedValueCollection const aEventDescriptor( rElement ); + + // create Configuration at first, creation might call this method also and that would overwrite everything + // we might have stored before! + if ( mpObjShell && !mpObjShell->IsLoading() ) { - // check for correct type of the element - if ( !::comphelper::NamedValueCollection::canExtractFrom( rElement ) ) - throw lang::IllegalArgumentException(); - ::comphelper::NamedValueCollection const aEventDescriptor( rElement ); - - // create Configuration at first, creation might call this method also and that would overwrite everything - // we might have stored before! - if ( mpObjShell && !mpObjShell->IsLoading() ) - mpObjShell->SetModified(); - - ::comphelper::NamedValueCollection aNormalizedDescriptor; - NormalizeMacro( aEventDescriptor, aNormalizedDescriptor, mpObjShell ); - - OUString sType; - if ( ( aNormalizedDescriptor.size() == 1 ) - && !aNormalizedDescriptor.has( PROP_EVENT_TYPE ) //TODO - && ( aNormalizedDescriptor.get( PROP_EVENT_TYPE ) >>= sType ) - && ( sType.isEmpty() ) - ) - { - // An empty event type means no binding. Therefore reset data - // to reflect that state. - // (that's for compatibility only. Nowadays, the Tools/Customize dialog should - // set an empty sequence to indicate the request for resetting the assignment.) - OSL_ENSURE( false, "legacy event assignment format detected" ); - aNormalizedDescriptor.clear(); - } + // SetModified will end up calling into our documentEventOccured method + aGuard.unlock(); + mpObjShell->SetModified(); + aGuard.lock(); + } - if ( !aNormalizedDescriptor.empty() ) - { - maEventData[nIndex] <<= aNormalizedDescriptor.getPropertyValues(); - } - else - { - maEventData[nIndex].clear(); - } - return; + ::comphelper::NamedValueCollection aNormalizedDescriptor; + NormalizeMacro( aEventDescriptor, aNormalizedDescriptor, mpObjShell ); + + OUString sType; + if ( ( aNormalizedDescriptor.size() == 1 ) + && !aNormalizedDescriptor.has( PROP_EVENT_TYPE ) //TODO + && ( aNormalizedDescriptor.get( PROP_EVENT_TYPE ) >>= sType ) + && ( sType.isEmpty() ) + ) + { + // An empty event type means no binding. Therefore reset data + // to reflect that state. + // (that's for compatibility only. Nowadays, the Tools/Customize dialog should + // set an empty sequence to indicate the request for resetting the assignment.) + OSL_ENSURE( false, "legacy event assignment format detected" ); + aNormalizedDescriptor.clear(); } - throw container::NoSuchElementException(); + if ( !aNormalizedDescriptor.empty() ) + { + maEventData[nIndex] <<= aNormalizedDescriptor.getPropertyValues(); + } + else + { + maEventData[nIndex].clear(); + } } @@ -109,7 +111,7 @@ void SAL_CALL SfxEvents_Impl::replaceByName( const OUString & aName, const uno:: uno::Any SAL_CALL SfxEvents_Impl::getByName( const OUString& aName ) { - ::osl::MutexGuard aGuard( maMutex ); + std::unique_lock aGuard( maMutex ); // find the event in the list and return the data @@ -129,7 +131,7 @@ uno::Sequence< OUString > SAL_CALL SfxEvents_Impl::getElementNames() sal_Bool SAL_CALL SfxEvents_Impl::hasByName( const OUString& aName ) { - ::osl::MutexGuard aGuard( maMutex ); + std::unique_lock aGuard( maMutex ); // find the event in the list and return the data @@ -148,7 +150,7 @@ uno::Type SAL_CALL SfxEvents_Impl::getElementType() sal_Bool SAL_CALL SfxEvents_Impl::hasElements() { - ::osl::MutexGuard aGuard( maMutex ); + std::unique_lock aGuard( maMutex ); return maEventNames.hasElements(); } @@ -282,7 +284,7 @@ void SfxEvents_Impl::Execute( uno::Any const & aEventData, const document::Docum void SAL_CALL SfxEvents_Impl::documentEventOccured( const document::DocumentEvent& aEvent ) { - ::osl::ClearableMutexGuard aGuard( maMutex ); + std::unique_lock aGuard( maMutex ); // get the event name, find the corresponding data, execute the data @@ -291,7 +293,7 @@ void SAL_CALL SfxEvents_Impl::documentEventOccured( const document::DocumentEven return; uno::Any aEventData = maEventData[ nIndex ]; - aGuard.clear(); + aGuard.unlock(); Execute( aEventData, aEvent, mpObjShell ); } @@ -300,7 +302,7 @@ void SAL_CALL SfxEvents_Impl::documentEventOccured( const document::DocumentEven void SAL_CALL SfxEvents_Impl::disposing( const lang::EventObject& /*Source*/ ) { - ::osl::MutexGuard aGuard( maMutex ); + std::unique_lock aGuard( maMutex ); if ( mxBroadcaster.is() ) {