diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-17 14:23:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-18 20:40:37 +0000 |
commit | 76bdc40cc3157a8ac98332047f8edbc4008f5392 (patch) | |
tree | 0c7c0a6a57ab5e81fdd803325b4386a707cef9df /toolkit/source | |
parent | a979535eeb1630334b60eea98be2c2fabec56c23 (diff) |
osl::Mutex->std::mutex in DefaultGridColumnModel
Change-Id: Ie3df092b013f10b36c85028fe3b9966d58b22005
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147264
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'toolkit/source')
-rw-r--r-- | toolkit/source/controls/grid/defaultgridcolumnmodel.cxx | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx index 64cf2a61b3e2..f498001d1173 100644 --- a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx @@ -29,9 +29,8 @@ #include <comphelper/sequence.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/componentguard.hxx> -#include <comphelper/interfacecontainer3.hxx> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <comphelper/interfacecontainer4.hxx> +#include <comphelper/compbase.hxx> #include <cppuhelper/supportsservice.hxx> #include <o3tl/safeint.hxx> #include <rtl/ref.hxx> @@ -49,12 +48,11 @@ using namespace toolkit; namespace { -typedef ::cppu::WeakComponentImplHelper < css::awt::grid::XGridColumnModel +typedef ::comphelper::WeakComponentImplHelper < css::awt::grid::XGridColumnModel , css::lang::XServiceInfo > DefaultGridColumnModel_Base; -class DefaultGridColumnModel :public ::cppu::BaseMutex - ,public DefaultGridColumnModel_Base +class DefaultGridColumnModel : public DefaultGridColumnModel_Base { public: DefaultGridColumnModel(); @@ -82,25 +80,20 @@ public: virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override; // OComponentHelper - virtual void SAL_CALL disposing() override; + virtual void disposing( std::unique_lock<std::mutex>& ) override; private: typedef ::std::vector< rtl::Reference< GridColumn > > Columns; - ::comphelper::OInterfaceContainerHelper3<XContainerListener> m_aContainerListeners; + ::comphelper::OInterfaceContainerHelper4<XContainerListener> m_aContainerListeners; Columns m_aColumns; }; DefaultGridColumnModel::DefaultGridColumnModel() - :DefaultGridColumnModel_Base( m_aMutex ) - ,m_aContainerListeners( m_aMutex ) { } DefaultGridColumnModel::DefaultGridColumnModel( DefaultGridColumnModel const & i_copySource ) - :cppu::BaseMutex() - ,DefaultGridColumnModel_Base( m_aMutex ) - ,m_aContainerListeners( m_aMutex ) { Columns aColumns; aColumns.reserve( i_copySource.m_aColumns.size() ); @@ -134,14 +127,16 @@ private: Reference< XGridColumn > SAL_CALL DefaultGridColumnModel::createColumn( ) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); return new GridColumn(); } ::sal_Int32 SAL_CALL DefaultGridColumnModel::addColumn( const Reference< XGridColumn > & i_column ) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); GridColumn* const pGridColumn = dynamic_cast<GridColumn*>( i_column.get() ); if ( pGridColumn == nullptr ) @@ -157,8 +152,7 @@ private: aEvent.Accessor <<= index; aEvent.Element <<= i_column; - aGuard.clear(); - m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); + m_aContainerListeners.notifyEach( aGuard, &XContainerListener::elementInserted, aEvent ); return index; } @@ -166,7 +160,8 @@ private: void SAL_CALL DefaultGridColumnModel::removeColumn( ::sal_Int32 i_columnIndex ) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); if ( ( i_columnIndex < 0 ) || ( o3tl::make_unsigned( i_columnIndex ) >= m_aColumns.size() ) ) throw css::lang::IndexOutOfBoundsException( OUString(), *this ); @@ -192,8 +187,9 @@ private: aEvent.Accessor <<= i_columnIndex; aEvent.Element <<= xColumn; - aGuard.clear(); - m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent ); + m_aContainerListeners.notifyEach( aGuard, &XContainerListener::elementRemoved, aEvent ); + + aGuard.unlock(); // dispose the removed column try @@ -209,14 +205,16 @@ private: Sequence< Reference< XGridColumn > > SAL_CALL DefaultGridColumnModel::getColumns() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); return ::comphelper::containerToSequence<Reference<XGridColumn>>( m_aColumns ); } Reference< XGridColumn > SAL_CALL DefaultGridColumnModel::getColumn(::sal_Int32 index) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); if ( index >=0 && o3tl::make_unsigned(index) < m_aColumns.size()) return m_aColumns[index]; @@ -230,57 +228,58 @@ private: ::std::vector< ContainerEvent > aRemovedColumns; ::std::vector< ContainerEvent > aInsertedColumns; - { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); - // remove existing columns - while ( !m_aColumns.empty() ) - { - const size_t lastColIndex = m_aColumns.size() - 1; + // remove existing columns + while ( !m_aColumns.empty() ) + { + const size_t lastColIndex = m_aColumns.size() - 1; - ContainerEvent aEvent; - aEvent.Source = *this; - aEvent.Accessor <<= sal_Int32( lastColIndex ); - aEvent.Element <<= Reference<XGridColumn>(m_aColumns[ lastColIndex ]); - aRemovedColumns.push_back( aEvent ); + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Accessor <<= sal_Int32( lastColIndex ); + aEvent.Element <<= Reference<XGridColumn>(m_aColumns[ lastColIndex ]); + aRemovedColumns.push_back( aEvent ); - m_aColumns.erase( m_aColumns.begin() + lastColIndex ); - } + m_aColumns.erase( m_aColumns.begin() + lastColIndex ); + } - // add new columns - for ( sal_Int32 i=0; i<rowElements; ++i ) - { - ::rtl::Reference< GridColumn > const pGridColumn = new GridColumn(); - OUString colTitle = "Column " + OUString::number( i + 1 ); - pGridColumn->setTitle( colTitle ); - pGridColumn->setColumnWidth( 80 /* APPFONT */ ); - pGridColumn->setFlexibility( 1 ); - pGridColumn->setResizeable( true ); - pGridColumn->setDataColumnIndex( i ); - - ContainerEvent aEvent; - aEvent.Source = *this; - aEvent.Accessor <<= i; - aEvent.Element <<= Reference<XGridColumn>(pGridColumn); - aInsertedColumns.push_back( aEvent ); - - m_aColumns.push_back( pGridColumn ); - pGridColumn->setIndex( i ); - } + // add new columns + for ( sal_Int32 i=0; i<rowElements; ++i ) + { + ::rtl::Reference< GridColumn > const pGridColumn = new GridColumn(); + OUString colTitle = "Column " + OUString::number( i + 1 ); + pGridColumn->setTitle( colTitle ); + pGridColumn->setColumnWidth( 80 /* APPFONT */ ); + pGridColumn->setFlexibility( 1 ); + pGridColumn->setResizeable( true ); + pGridColumn->setDataColumnIndex( i ); + + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Accessor <<= i; + aEvent.Element <<= Reference<XGridColumn>(pGridColumn); + aInsertedColumns.push_back( aEvent ); + + m_aColumns.push_back( pGridColumn ); + pGridColumn->setIndex( i ); } // fire removal notifications for (const auto& rEvent : aRemovedColumns) { - m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, rEvent ); + m_aContainerListeners.notifyEach( aGuard, &XContainerListener::elementRemoved, rEvent ); } // fire insertion notifications for (const auto& rEvent : aInsertedColumns) { - m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, rEvent ); + m_aContainerListeners.notifyEach( aGuard, &XContainerListener::elementInserted, rEvent ); } + aGuard.unlock(); + // dispose removed columns for (const auto& rEvent : aRemovedColumns) { @@ -315,26 +314,26 @@ private: void SAL_CALL DefaultGridColumnModel::addContainerListener( const Reference< XContainerListener >& i_listener ) { + std::unique_lock aGuard(m_aMutex); if ( i_listener.is() ) - m_aContainerListeners.addInterface( i_listener ); + m_aContainerListeners.addInterface( aGuard, i_listener ); } void SAL_CALL DefaultGridColumnModel::removeContainerListener( const Reference< XContainerListener >& i_listener ) { + std::unique_lock aGuard(m_aMutex); if ( i_listener.is() ) - m_aContainerListeners.removeInterface( i_listener ); + m_aContainerListeners.removeInterface( aGuard, i_listener ); } - void SAL_CALL DefaultGridColumnModel::disposing() + void DefaultGridColumnModel::disposing( std::unique_lock<std::mutex>& rGuard ) { - DefaultGridColumnModel_Base::disposing(); + DefaultGridColumnModel_Base::disposing(rGuard); EventObject aEvent( *this ); - m_aContainerListeners.disposeAndClear( aEvent ); - - ::osl::MutexGuard aGuard( m_aMutex ); + m_aContainerListeners.disposeAndClear( rGuard, aEvent ); // remove, dispose and clear columns while ( !m_aColumns.empty() ) @@ -357,7 +356,8 @@ private: Reference< css::util::XCloneable > SAL_CALL DefaultGridColumnModel::createClone( ) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + throwIfDisposed(aGuard); return new DefaultGridColumnModel( *this ); } |