diff options
-rw-r--r-- | comphelper/source/container/enumhelper.cxx | 28 | ||||
-rw-r--r-- | include/comphelper/enumhelper.hxx | 23 |
2 files changed, 22 insertions, 29 deletions
diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx index edcb03c669cc..2487d3adf234 100644 --- a/comphelper/source/container/enumhelper.cxx +++ b/comphelper/source/container/enumhelper.cxx @@ -48,13 +48,15 @@ OEnumerationByName::OEnumerationByName(const css::uno::Reference<css::container: OEnumerationByName::~OEnumerationByName() { + std::lock_guard aLock(m_aLock); + impl_stopDisposeListening(); } sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( ) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); if (m_xAccess.is() && m_aNames.getLength() > m_nPos) return true; @@ -71,7 +73,7 @@ sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( ) css::uno::Any SAL_CALL OEnumerationByName::nextElement( ) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); css::uno::Any aRes; if (m_xAccess.is() && m_nPos < m_aNames.getLength()) @@ -92,7 +94,7 @@ css::uno::Any SAL_CALL OEnumerationByName::nextElement( ) void SAL_CALL OEnumerationByName::disposing(const css::lang::EventObject& aEvent) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); if (aEvent.Source == m_xAccess) m_xAccess.clear(); @@ -101,8 +103,6 @@ void SAL_CALL OEnumerationByName::disposing(const css::lang::EventObject& aEvent void OEnumerationByName::impl_startDisposeListening() { - osl::MutexGuard aLock(m_aLock); - if (m_bListening) return; @@ -119,8 +119,6 @@ void OEnumerationByName::impl_startDisposeListening() void OEnumerationByName::impl_stopDisposeListening() { - osl::MutexGuard aLock(m_aLock); - if (!m_bListening) return; @@ -145,13 +143,15 @@ OEnumerationByIndex::OEnumerationByIndex(const css::uno::Reference< css::contain OEnumerationByIndex::~OEnumerationByIndex() { + std::lock_guard aLock(m_aLock); + impl_stopDisposeListening(); } sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( ) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); if (m_xAccess.is() && m_xAccess->getCount() > m_nPos) return true; @@ -168,7 +168,7 @@ sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( ) css::uno::Any SAL_CALL OEnumerationByIndex::nextElement( ) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); css::uno::Any aRes; if (m_xAccess.is() && m_nPos < m_xAccess->getCount()) @@ -188,7 +188,7 @@ css::uno::Any SAL_CALL OEnumerationByIndex::nextElement( ) void SAL_CALL OEnumerationByIndex::disposing(const css::lang::EventObject& aEvent) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); if (aEvent.Source == m_xAccess) m_xAccess.clear(); @@ -197,8 +197,6 @@ void SAL_CALL OEnumerationByIndex::disposing(const css::lang::EventObject& aEven void OEnumerationByIndex::impl_startDisposeListening() { - osl::MutexGuard aLock(m_aLock); - if (m_bListening) return; @@ -215,8 +213,6 @@ void OEnumerationByIndex::impl_startDisposeListening() void OEnumerationByIndex::impl_stopDisposeListening() { - osl::MutexGuard aLock(m_aLock); - if (!m_bListening) return; @@ -244,7 +240,7 @@ OAnyEnumeration::~OAnyEnumeration() sal_Bool SAL_CALL OAnyEnumeration::hasMoreElements( ) { - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); return (m_lItems.getLength() > m_nPos); } @@ -255,7 +251,7 @@ css::uno::Any SAL_CALL OAnyEnumeration::nextElement( ) if ( ! hasMoreElements()) throw css::container::NoSuchElementException(); - osl::MutexGuard aLock(m_aLock); + std::lock_guard aLock(m_aLock); sal_Int32 nPos = m_nPos; ++m_nPos; return m_lItems[nPos]; diff --git a/include/comphelper/enumhelper.hxx b/include/comphelper/enumhelper.hxx index 5e5e000d78df..52f3aa743ade 100644 --- a/include/comphelper/enumhelper.hxx +++ b/include/comphelper/enumhelper.hxx @@ -23,7 +23,7 @@ #include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/lang/XEventListener.hpp> #include <cppuhelper/implbase.hxx> -#include <osl/mutex.hxx> +#include <mutex> #include <comphelper/comphelperdllapi.h> namespace com::sun::star::container { class XIndexAccess; } @@ -32,23 +32,18 @@ namespace com::sun::star::container { class XNameAccess; } namespace comphelper { -struct OEnumerationLock -{ - public: - ::osl::Mutex m_aLock; -}; - /** provides a com.sun.star.container::XEnumeration access based on an object implementing the com.sun.star.container::XNameAccess interface */ -class COMPHELPER_DLLPUBLIC OEnumerationByName final : private OEnumerationLock - , public ::cppu::WeakImplHelper< css::container::XEnumeration , +class COMPHELPER_DLLPUBLIC OEnumerationByName final : + public ::cppu::WeakImplHelper< css::container::XEnumeration , css::lang::XEventListener > { css::uno::Sequence< OUString > const m_aNames; css::uno::Reference< css::container::XNameAccess > m_xAccess; sal_Int32 m_nPos; bool m_bListening; + std::mutex m_aLock; public: OEnumerationByName(const css::uno::Reference< css::container::XNameAccess >& _rxAccess); @@ -69,13 +64,14 @@ private: /** provides a com.sun.star.container::XEnumeration access based on an object implementing the com.sun.star.container::XNameAccess interface */ -class COMPHELPER_DLLPUBLIC OEnumerationByIndex final : private OEnumerationLock - , public ::cppu::WeakImplHelper< css::container::XEnumeration , +class COMPHELPER_DLLPUBLIC OEnumerationByIndex final : + public ::cppu::WeakImplHelper< css::container::XEnumeration , css::lang::XEventListener > { css::uno::Reference< css::container::XIndexAccess > m_xAccess; sal_Int32 m_nPos; bool m_bListening; + std::mutex m_aLock; public: OEnumerationByIndex(const css::uno::Reference< css::container::XIndexAccess >& _rxAccess); @@ -99,11 +95,12 @@ class SAL_DLLPUBLIC_TEMPLATE OAnyEnumeration_BASE for an outside set vector of Any's. */ -class COMPHELPER_DLLPUBLIC OAnyEnumeration final : private OEnumerationLock - , public OAnyEnumeration_BASE +class COMPHELPER_DLLPUBLIC OAnyEnumeration final : + public OAnyEnumeration_BASE { sal_Int32 m_nPos; css::uno::Sequence< css::uno::Any > m_lItems; + std::mutex m_aLock; public: OAnyEnumeration(const css::uno::Sequence< css::uno::Any >& lItems); |