From 89ec1375f3f6bf7c390be29b2637e14d23bb0dfe Mon Sep 17 00:00:00 2001 From: hogliux Date: Thu, 19 Apr 2018 11:05:54 +0100 Subject: [PATCH] Adding missing locks in ListenerList when the underlying array of the ListenerList uses a CriticalSection --- modules/juce_core/containers/juce_ListenerList.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/juce_core/containers/juce_ListenerList.h b/modules/juce_core/containers/juce_ListenerList.h index 6e537ee879..493ece2a0b 100644 --- a/modules/juce_core/containers/juce_ListenerList.h +++ b/modules/juce_core/containers/juce_ListenerList.h @@ -118,6 +118,8 @@ public: template void call (Callback&& callback) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next();) callback (*iter.getListener()); } @@ -128,6 +130,8 @@ public: template void callExcluding (ListenerClass* listenerToExclude, Callback&& callback) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next();) { auto* l = iter.getListener(); @@ -143,6 +147,8 @@ public: template void callChecked (const BailOutCheckerType& bailOutChecker, Callback&& callback) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next (bailOutChecker);) callback (*iter.getListener()); } @@ -156,6 +162,8 @@ public: const BailOutCheckerType& bailOutChecker, Callback&& callback) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next (bailOutChecker);) { auto* l = iter.getListener(); @@ -252,6 +260,8 @@ public: template void call (void (ListenerClass::*callbackFunction) (MethodArgs...), Args&&... args) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next();) (iter.getListener()->*callbackFunction) (static_cast::type> (args)...); } @@ -261,6 +271,8 @@ public: void (ListenerClass::*callbackFunction) (MethodArgs...), Args&&... args) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next();) if (iter.getListener() != listenerToExclude) (iter.getListener()->*callbackFunction) (static_cast::type> (args)...); @@ -271,6 +283,8 @@ public: void (ListenerClass::*callbackFunction) (MethodArgs...), Args&&... args) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next (bailOutChecker);) (iter.getListener()->*callbackFunction) (static_cast::type> (args)...); } @@ -281,6 +295,8 @@ public: void (ListenerClass::*callbackFunction) (MethodArgs...), Args&&... args) { + typename ArrayType::ScopedLockType lock (listeners.getLock()); + for (Iterator iter (*this); iter.next (bailOutChecker);) if (iter.getListener() != listenerToExclude) (iter.getListener()->*callbackFunction) (static_cast::type> (args)...);