diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2022-05-08 21:33:51 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-10 19:26:30 +0200 |
commit | 3b2888fe0971b07d647a29467c317ba42a51b832 (patch) | |
tree | 8114a79bab14e7594b81fe7ab0d0f937eddc5ecc /ucb | |
parent | f75b742997c119ccb081faa7e63ce04b8e88912c (diff) |
osl::Mutex->std::mutex in ucb::XResultSet_impl
Change-Id: I67f70774c94d953880ebcf9fe9bf24a0492456f6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134085
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/file/filrset.cxx | 98 | ||||
-rw-r--r-- | ucb/source/ucp/file/filrset.hxx | 14 |
2 files changed, 43 insertions, 69 deletions
diff --git a/ucb/source/ucp/file/filrset.cxx b/ucb/source/ucp/file/filrset.cxx index 5d880cc4a819..5f0d4ec3a25c 100644 --- a/ucb/source/ucp/file/filrset.cxx +++ b/ucb/source/ucp/file/filrset.cxx @@ -96,13 +96,9 @@ void SAL_CALL XResultSet_impl::addEventListener( const uno::Reference< lang::XEventListener >& Listener ) { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); - if ( ! m_pDisposeEventListeners ) - m_pDisposeEventListeners.reset( - new comphelper::OInterfaceContainerHelper3<lang::XEventListener>( m_aEventListenerMutex ) ); - - m_pDisposeEventListeners->addInterface( Listener ); + m_aDisposeEventListeners.addInterface( aGuard, Listener ); } @@ -110,47 +106,32 @@ void SAL_CALL XResultSet_impl::removeEventListener( const uno::Reference< lang::XEventListener >& Listener ) { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); - if ( m_pDisposeEventListeners ) - m_pDisposeEventListeners->removeInterface( Listener ); + m_aDisposeEventListeners.removeInterface( aGuard, Listener ); } void SAL_CALL XResultSet_impl::dispose() { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); lang::EventObject aEvt; aEvt.Source = static_cast< lang::XComponent * >( this ); - if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) - { - m_pDisposeEventListeners->disposeAndClear( aEvt ); - } - if( m_pRowCountListeners && m_pRowCountListeners->getLength() ) - { - m_pRowCountListeners->disposeAndClear( aEvt ); - } - if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() ) - { - m_pIsFinalListeners->disposeAndClear( aEvt ); - } + m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt ); + m_aRowCountListeners.disposeAndClear( aGuard, aEvt ); + m_aIsFinalListeners.disposeAndClear( aGuard, aEvt ); } -void XResultSet_impl::rowCountChanged() +void XResultSet_impl::rowCountChanged(std::unique_lock<std::mutex>& rGuard) { sal_Int32 aOldValue,aNewValue; - std::vector< uno::Reference< beans::XPropertyChangeListener > > seq; - { - osl::MutexGuard aGuard( m_aMutex ); - if( m_pRowCountListeners ) - seq = m_pRowCountListeners->getElements(); - aNewValue = m_aItems.size(); - aOldValue = aNewValue-1; - } + std::vector< uno::Reference< beans::XPropertyChangeListener > > seq = m_aRowCountListeners.getElements(rGuard); + aNewValue = m_aItems.size(); + aOldValue = aNewValue-1; beans::PropertyChangeEvent aEv; aEv.PropertyName = "RowCount"; aEv.Further = false; @@ -166,9 +147,8 @@ void XResultSet_impl::isFinalChanged() { std::vector< uno::Reference< beans::XPropertyChangeListener > > seq; { - osl::MutexGuard aGuard( m_aMutex ); - if( m_pIsFinalListeners ) - seq = m_pIsFinalListeners->getElements(); + std::unique_lock aGuard( m_aMutex ); + seq = m_aIsFinalListeners.getElements(aGuard); m_bRowCountFinal = true; } beans::PropertyChangeEvent aEv; @@ -217,11 +197,11 @@ XResultSet_impl::OneMore() if( m_nOpenMode == ucb::OpenMode::DOCUMENTS && IsRegular ) { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); m_aItems.push_back( aRow ); m_aIdents.emplace_back( ); m_aUnqPath.push_back( aUnqPath ); - rowCountChanged(); + rowCountChanged(aGuard); return true; } @@ -231,11 +211,11 @@ XResultSet_impl::OneMore() } else if( m_nOpenMode == ucb::OpenMode::FOLDERS && ! IsRegular ) { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); m_aItems.push_back( aRow ); m_aIdents.emplace_back( ); m_aUnqPath.push_back( aUnqPath ); - rowCountChanged(); + rowCountChanged(aGuard); return true; } else if( m_nOpenMode == ucb::OpenMode::FOLDERS && IsRegular ) @@ -244,11 +224,11 @@ XResultSet_impl::OneMore() } else { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); m_aItems.push_back( aRow ); m_aIdents.emplace_back( ); m_aUnqPath.push_back( aUnqPath ); - rowCountChanged(); + rowCountChanged(aGuard); return true; } } @@ -435,7 +415,7 @@ XResultSet_impl::close() { m_aFolder.close(); isFinalChanged(); - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); m_nIsOpen = false; } } @@ -486,7 +466,7 @@ XResultSet_impl::queryContent() uno::Reference< sdbc::XResultSet > SAL_CALL XResultSet_impl::getStaticResultSet() { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( m_xListener.is() ) throw ucb::ListenerAlreadySetException( THROW_WHERE ); @@ -500,7 +480,7 @@ void SAL_CALL XResultSet_impl::setListener( const uno::Reference< ucb::XDynamicResultSetListener >& Listener ) { - osl::ClearableMutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( m_xListener.is() ) throw ucb::ListenerAlreadySetException( THROW_WHERE ); @@ -525,7 +505,7 @@ XResultSet_impl::setListener( 0, // Count; not used ucb::ListActionType::WELCOME, aInfo ); - aGuard.clear(); + aGuard.unlock(); Listener->notify( ucb::ListEvent( @@ -648,20 +628,15 @@ void SAL_CALL XResultSet_impl::addPropertyChangeListener( { if( aPropertyName == "IsRowCountFinal" ) { - osl::MutexGuard aGuard( m_aMutex ); - if ( ! m_pIsFinalListeners ) - m_pIsFinalListeners.reset( - new comphelper::OInterfaceContainerHelper3<beans::XPropertyChangeListener>( m_aEventListenerMutex ) ); + std::unique_lock aGuard( m_aMutex ); - m_pIsFinalListeners->addInterface( xListener ); + m_aIsFinalListeners.addInterface( aGuard, xListener ); } else if ( aPropertyName == "RowCount" ) { - osl::MutexGuard aGuard( m_aMutex ); - if ( ! m_pRowCountListeners ) - m_pRowCountListeners.reset( - new comphelper::OInterfaceContainerHelper3<beans::XPropertyChangeListener>( m_aEventListenerMutex ) ); - m_pRowCountListeners->addInterface( xListener ); + std::unique_lock aGuard( m_aMutex ); + + m_aRowCountListeners.addInterface( aGuard, xListener ); } else throw beans::UnknownPropertyException( aPropertyName ); @@ -672,18 +647,17 @@ void SAL_CALL XResultSet_impl::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) { - if( aPropertyName == "IsRowCountFinal" && - m_pIsFinalListeners ) + if( aPropertyName == "IsRowCountFinal" ) { - osl::MutexGuard aGuard( m_aMutex ); - m_pIsFinalListeners->removeInterface( aListener ); + std::unique_lock aGuard( m_aMutex ); + + m_aIsFinalListeners.removeInterface( aGuard, aListener ); } - else if ( aPropertyName == "RowCount" && - m_pRowCountListeners ) + else if ( aPropertyName == "RowCount" ) { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); - m_pRowCountListeners->removeInterface( aListener ); + m_aRowCountListeners.removeInterface( aGuard, aListener ); } else throw beans::UnknownPropertyException( aPropertyName ); diff --git a/ucb/source/ucp/file/filrset.hxx b/ucb/source/ucp/file/filrset.hxx index a1457e76ea79..3361405dd5ed 100644 --- a/ucb/source/ucp/file/filrset.hxx +++ b/ucb/source/ucp/file/filrset.hxx @@ -18,10 +18,11 @@ */ #pragma once +#include <mutex> #include <vector> #include <osl/file.hxx> -#include <comphelper/interfacecontainer3.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <com/sun/star/ucb/XContentAccess.hpp> #include <com/sun/star/sdbc/XCloseable.hpp> #include <com/sun/star/beans/XPropertySet.hpp> @@ -407,11 +408,10 @@ class XResultSet_impl : css::uno::Sequence< css::beans::Property > m_sProperty; css::uno::Sequence< css::ucb::NumberedSortingInfo > m_sSortingInfo; - osl::Mutex m_aMutex; - osl::Mutex m_aEventListenerMutex; - std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::lang::XEventListener>> m_pDisposeEventListeners; - std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::beans::XPropertyChangeListener>> m_pRowCountListeners; - std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::beans::XPropertyChangeListener>> m_pIsFinalListeners; + std::mutex m_aMutex; + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aDisposeEventListeners; + comphelper::OInterfaceContainerHelper4<css::beans::XPropertyChangeListener> m_aRowCountListeners; + comphelper::OInterfaceContainerHelper4<css::beans::XPropertyChangeListener> m_aIsFinalListeners; css::uno::Reference< css::ucb::XDynamicResultSetListener > m_xListener; @@ -423,7 +423,7 @@ class XResultSet_impl : /// @throws css::uno::RuntimeException bool OneMore(); - void rowCountChanged(); + void rowCountChanged(std::unique_lock<std::mutex>&); void isFinalChanged(); }; |