diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-19 15:28:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-02-19 18:28:57 +0000 |
commit | 414172d7fafc2d2c6b1e698aeb67fdb5797b118d (patch) | |
tree | ef761311ee05e2d9bee8b2b64fddcf7b589c91f0 /include/comphelper/interfacecontainer4.hxx | |
parent | 0b44a7760dc2093564bbded0afce6c749dd307ae (diff) |
fix locking in OMultiTypeInterfaceContainerHelperVar4::diposeAndCloear
where I forgot to relock at the end of the method
And sprinkle some asserts around to catch mistakes like this in future
Change-Id: I4908ac0ffdfe33b1b5cf1b02e6765f20973af841
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147296
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/comphelper/interfacecontainer4.hxx')
-rw-r--r-- | include/comphelper/interfacecontainer4.hxx | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/include/comphelper/interfacecontainer4.hxx b/include/comphelper/interfacecontainer4.hxx index 3a6696fda8c5..bfa3a3059212 100644 --- a/include/comphelper/interfacecontainer4.hxx +++ b/include/comphelper/interfacecontainer4.hxx @@ -60,13 +60,15 @@ public: @param rGuard this parameter only here to make that this container is accessed while locked */ - OInterfaceIteratorHelper4(std::unique_lock<std::mutex>& /*rGuard*/, + OInterfaceIteratorHelper4(std::unique_lock<std::mutex>& rGuard, OInterfaceContainerHelper4<ListenerT>& rCont_) : rCont(rCont_) , maData(rCont.maData) // const_cast so we don't trigger make_unique via o3tl::cow_wrapper::operator-> , nRemain(std::as_const(maData)->size()) { + assert(rGuard.owns_lock()); + (void)rGuard; } /** Return true, if there are more elements in the iterator. */ @@ -281,6 +283,7 @@ template <typename FuncT> inline void OInterfaceContainerHelper4<T>::forEach(std::unique_lock<std::mutex>& rGuard, FuncT const& func) const { + assert(rGuard.owns_lock()); if (std::as_const(maData)->size() == 0) { return; @@ -321,23 +324,29 @@ inline void OInterfaceContainerHelper4<ListenerT>::notifyEach( template <class ListenerT> sal_Int32 -OInterfaceContainerHelper4<ListenerT>::getLength(std::unique_lock<std::mutex>& /*rGuard*/) const +OInterfaceContainerHelper4<ListenerT>::getLength(std::unique_lock<std::mutex>& rGuard) const { + assert(rGuard.owns_lock()); + (void)rGuard; return maData->size(); } template <class ListenerT> std::vector<css::uno::Reference<ListenerT>> -OInterfaceContainerHelper4<ListenerT>::getElements(std::unique_lock<std::mutex>& /*rGuard*/) const +OInterfaceContainerHelper4<ListenerT>::getElements(std::unique_lock<std::mutex>& rGuard) const { + assert(rGuard.owns_lock()); + (void)rGuard; return *maData; } template <class ListenerT> sal_Int32 -OInterfaceContainerHelper4<ListenerT>::addInterface(std::unique_lock<std::mutex>& /*rGuard*/, +OInterfaceContainerHelper4<ListenerT>::addInterface(std::unique_lock<std::mutex>& rGuard, const css::uno::Reference<ListenerT>& rListener) { + assert(rGuard.owns_lock()); + (void)rGuard; assert(rListener.is()); maData->push_back(rListener); return maData->size(); @@ -345,8 +354,10 @@ OInterfaceContainerHelper4<ListenerT>::addInterface(std::unique_lock<std::mutex> template <class ListenerT> sal_Int32 OInterfaceContainerHelper4<ListenerT>::removeInterface( - std::unique_lock<std::mutex>& /*rGuard*/, const css::uno::Reference<ListenerT>& rListener) + std::unique_lock<std::mutex>& rGuard, const css::uno::Reference<ListenerT>& rListener) { + assert(rGuard.owns_lock()); + (void)rGuard; assert(rListener.is()); // It is not valid to compare the pointer directly, but it's faster. @@ -395,8 +406,10 @@ void OInterfaceContainerHelper4<ListenerT>::disposeAndClear(std::unique_lock<std } template <class ListenerT> -void OInterfaceContainerHelper4<ListenerT>::clear(::std::unique_lock<::std::mutex>& /*rGuard*/) +void OInterfaceContainerHelper4<ListenerT>::clear(::std::unique_lock<::std::mutex>& rGuard) { + assert(rGuard.owns_lock()); + (void)rGuard; maData->clear(); } } |