diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-16 14:31:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-16 18:49:33 +0000 |
commit | 9301f4d486b13dac2a66b797d5e24eb6dc9f7582 (patch) | |
tree | 7fe0ebd5ecb197034c291e7b44c15b66edb387f8 | |
parent | 0d3361aa989bbdb334cc13690a5fe1698bbf0db5 (diff) |
osl::Mutex->std::mutex in ResultSetDataSupplier
Change-Id: I75cbf133e2e632c41759515fdf8894faed599c8d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147159
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | ucb/source/ucp/tdoc/tdoc_datasupplier.cxx | 50 | ||||
-rw-r--r-- | ucb/source/ucp/tdoc/tdoc_datasupplier.hxx | 15 |
2 files changed, 43 insertions, 22 deletions
diff --git a/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx b/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx index 206751eff193..f4291f4a5043 100644 --- a/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx +++ b/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx @@ -72,8 +72,13 @@ ResultSetDataSupplier::~ResultSetDataSupplier() OUString ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); + return queryContentIdentifierStringImpl(aGuard, nIndex); +} +OUString +ResultSetDataSupplier::queryContentIdentifierStringImpl( std::unique_lock<std::mutex>& /*rGuard*/, sal_uInt32 nIndex ) +{ if ( nIndex < m_aResults.size() ) { OUString aId = m_aResults[ nIndex ].aURL; @@ -96,8 +101,13 @@ ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) uno::Reference< ucb::XContentIdentifier > ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); + return queryContentIdentifierImpl(aGuard, nIndex); +} +uno::Reference< ucb::XContentIdentifier > +ResultSetDataSupplier::queryContentIdentifierImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex ) +{ if ( nIndex < m_aResults.size() ) { uno::Reference< ucb::XContentIdentifier > xId @@ -109,7 +119,7 @@ ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) } } - OUString aId = queryContentIdentifierString( nIndex ); + OUString aId = queryContentIdentifierStringImpl( rGuard, nIndex ); if ( !aId.isEmpty() ) { uno::Reference< ucb::XContentIdentifier > xId @@ -124,7 +134,7 @@ ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) uno::Reference< ucb::XContent > ResultSetDataSupplier::queryContent( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( nIndex < m_aResults.size() ) { @@ -138,7 +148,7 @@ ResultSetDataSupplier::queryContent( sal_uInt32 nIndex ) } uno::Reference< ucb::XContentIdentifier > xId - = queryContentIdentifier( nIndex ); + = queryContentIdentifierImpl( aGuard, nIndex ); if ( xId.is() ) { try @@ -159,8 +169,12 @@ ResultSetDataSupplier::queryContent( sal_uInt32 nIndex ) // virtual bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex ) { - osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); + return getResultImpl(aGuard, nIndex); +} +bool ResultSetDataSupplier::getResultImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex ) +{ if ( m_aResults.size() > nIndex ) { // Result already present. @@ -177,7 +191,7 @@ bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex ) sal_uInt32 nOldCount = m_aResults.size(); bool bFound = false; - if ( queryNamesOfChildren() ) + if ( queryNamesOfChildren(rGuard) ) { for ( sal_uInt32 n = nOldCount; n < sal::static_int_cast<sal_uInt32>( @@ -214,13 +228,15 @@ bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex ) if ( xResultSet.is() ) { // Callbacks follow! - aGuard.clear(); + rGuard.unlock(); if ( nOldCount < m_aResults.size() ) xResultSet->rowCountChanged( nOldCount, m_aResults.size() ); if ( m_bCountFinal ) xResultSet->rowCountFinal(); + + rGuard.lock(); } return bFound; @@ -229,14 +245,14 @@ bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex ) // virtual sal_uInt32 ResultSetDataSupplier::totalCount() { - osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( m_bCountFinal ) return m_aResults.size(); sal_uInt32 nOldCount = m_aResults.size(); - if ( queryNamesOfChildren() ) + if ( queryNamesOfChildren(aGuard) ) { for ( sal_uInt32 n = nOldCount; n < sal::static_int_cast<sal_uInt32>( @@ -265,7 +281,7 @@ sal_uInt32 ResultSetDataSupplier::totalCount() if ( xResultSet.is() ) { // Callbacks follow! - aGuard.clear(); + aGuard.unlock(); if ( nOldCount < m_aResults.size() ) xResultSet->rowCountChanged( nOldCount, m_aResults.size() ); @@ -292,7 +308,7 @@ bool ResultSetDataSupplier::isCountFinal() uno::Reference< sdbc::XRow > ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( nIndex < m_aResults.size() ) { @@ -304,13 +320,13 @@ ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex ) } } - if ( getResult( nIndex ) ) + if ( getResultImpl( aGuard, nIndex ) ) { uno::Reference< sdbc::XRow > xRow = Content::getPropertyValues( m_xContext, getResultSet()->getProperties(), m_xContent->getContentProvider().get(), - queryContentIdentifierString( nIndex ) ); + queryContentIdentifierStringImpl( aGuard, nIndex ) ); m_aResults[ nIndex ].xRow = xRow; return xRow; } @@ -321,7 +337,7 @@ ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex ) // virtual void ResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex ) { - osl::Guard< osl::Mutex > aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if ( nIndex < m_aResults.size() ) m_aResults[ nIndex ].xRow.clear(); @@ -339,10 +355,8 @@ void ResultSetDataSupplier::validate() throw ucb::ResultSetException(); } -bool ResultSetDataSupplier::queryNamesOfChildren() +bool ResultSetDataSupplier::queryNamesOfChildren(std::unique_lock<std::mutex>& /*rGuard*/) { - osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( !m_xNamesOfChildren ) { uno::Sequence< OUString > aNamesOfChildren; diff --git a/ucb/source/ucp/tdoc/tdoc_datasupplier.hxx b/ucb/source/ucp/tdoc/tdoc_datasupplier.hxx index 9b002a68637f..802a6dbc0a8c 100644 --- a/ucb/source/ucp/tdoc/tdoc_datasupplier.hxx +++ b/ucb/source/ucp/tdoc/tdoc_datasupplier.hxx @@ -21,17 +21,18 @@ #include <rtl/ref.hxx> #include <ucbhelper/resultset.hxx> +#include <mutex> #include <optional> +#include <string_view> #include <utility> #include <vector> -#include <string_view> namespace tdoc_ucp { struct DataSupplier_Impl; class Content; -class ResultSetDataSupplier : public ::ucbhelper::ResultSetDataSupplier +class ResultSetDataSupplier final : public ::ucbhelper::ResultSetDataSupplier { struct ResultListEntry { @@ -43,7 +44,7 @@ class ResultSetDataSupplier : public ::ucbhelper::ResultSetDataSupplier explicit ResultListEntry( OUString _aURL ) : aURL(std::move( _aURL )) {} }; - osl::Mutex m_aMutex; + std::mutex m_aMutex; std::vector< ResultListEntry > m_aResults; rtl::Reference< Content > m_xContent; css::uno::Reference< css::uno::XComponentContext > m_xContext; @@ -52,7 +53,7 @@ class ResultSetDataSupplier : public ::ucbhelper::ResultSetDataSupplier bool m_bThrowException; private: - bool queryNamesOfChildren(); + bool queryNamesOfChildren(std::unique_lock<std::mutex>& rGuard); OUString assembleChildURL( std::u16string_view aName ); public: @@ -80,6 +81,12 @@ public: virtual void close() override; virtual void validate() override; + +private: + OUString queryContentIdentifierStringImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex ); + css::uno::Reference< css::ucb::XContentIdentifier > + queryContentIdentifierImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex ); + bool getResultImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex ); }; } // namespace tdoc_ucp |