From 604c464e35807c7e4fa700726a338a9682010a15 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 25 Feb 2023 16:47:39 +0200 Subject: [PATCH] osl::Mutex->std::mutex in xmlscript::DocumentHandlerImpl Change-Id: If956c1e09e0185e7966edc17e2941b3f5d86c98f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147681 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmlscript/source/xml_helper/xml_impctx.cxx | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/xmlscript/source/xml_helper/xml_impctx.cxx b/xmlscript/source/xml_helper/xml_impctx.cxx index 1b4247ba822a..000de7e94072 100644 --- a/xmlscript/source/xml_helper/xml_impctx.cxx +++ b/xmlscript/source/xml_helper/xml_impctx.cxx @@ -31,6 +31,8 @@ #include #include +#include +#include #include #include @@ -75,13 +77,13 @@ class ExtendedAttributes; class MGuard { - Mutex * m_pMutex; + std::mutex * m_pMutex; public: - explicit MGuard( std::unique_ptr const & pMutex ) - : m_pMutex( pMutex.get() ) - { if (m_pMutex) m_pMutex->acquire(); } + explicit MGuard( std::optional & oMutex ) + : m_pMutex( oMutex ? &*oMutex : nullptr ) + { if (m_pMutex) m_pMutex->lock(); } ~MGuard() noexcept - { if (m_pMutex) m_pMutex->release(); } + { if (m_pMutex) m_pMutex->unlock(); } }; class DocumentHandlerImpl : @@ -107,7 +109,7 @@ class DocumentHandlerImpl : std::vector< ElementEntry > m_elements; sal_Int32 m_nSkipElements; - std::unique_ptr m_pMutex; + mutable std::optional m_oMutex; inline Reference< xml::input::XElement > getCurrentElement() const; @@ -178,13 +180,13 @@ DocumentHandlerImpl::DocumentHandlerImpl( m_elements.reserve( 10 ); if (! bSingleThreadedUse) - m_pMutex.reset(new Mutex); + m_oMutex.emplace(); } inline Reference< xml::input::XElement > DocumentHandlerImpl::getCurrentElement() const { - MGuard aGuard( m_pMutex ); + MGuard aGuard( m_oMutex ); if (m_elements.empty()) return Reference< xml::input::XElement >(); else @@ -193,7 +195,7 @@ DocumentHandlerImpl::getCurrentElement() const inline sal_Int32 DocumentHandlerImpl::getUidByURI( OUString const & rURI ) { - MGuard guard( m_pMutex ); + MGuard guard( m_oMutex ); if (m_nLastURI_lookup == UID_UNKNOWN || m_aLastURI_lookup != rURI) { t_OUString2LongMap::const_iterator iFind( m_URI2Uid.find( rURI ) ); @@ -370,7 +372,7 @@ Sequence< OUString > DocumentHandlerImpl::getSupportedServiceNames() void DocumentHandlerImpl::initialize( Sequence< Any > const & arguments ) { - MGuard guard( m_pMutex ); + MGuard guard( m_oMutex ); Reference< xml::input::XRoot > xRoot; if (arguments.getLength() != 1 || !(arguments[ 0 ] >>= xRoot) || @@ -392,7 +394,7 @@ sal_Int32 DocumentHandlerImpl::getUidByUri( OUString const & Uri ) OUString DocumentHandlerImpl::getUriByUid( sal_Int32 Uid ) { - MGuard guard( m_pMutex ); + MGuard guard( m_oMutex ); for (const auto& rURIUid : m_URI2Uid) { if (rURIUid.second == Uid) @@ -424,7 +426,7 @@ void DocumentHandlerImpl::startElement( ElementEntry elementEntry; { // guard start: - MGuard aGuard( m_pMutex ); + MGuard aGuard( m_oMutex ); // currently skipping elements and waiting for end tags? if (m_nSkipElements > 0) { @@ -526,7 +528,7 @@ void DocumentHandlerImpl::startElement( } { - MGuard aGuard( m_pMutex ); + MGuard aGuard( m_oMutex ); if (elementEntry.m_xElement.is()) { m_elements.push_back( std::move(elementEntry) ); @@ -549,7 +551,7 @@ void DocumentHandlerImpl::endElement( { Reference< xml::input::XElement > xCurrentElement; { - MGuard aGuard( m_pMutex ); + MGuard aGuard( m_oMutex ); if (m_nSkipElements) { --m_nSkipElements;