diff --git a/modules/juce_core/containers/juce_ListenerList.h b/modules/juce_core/containers/juce_ListenerList.h index 4401f2af4f..bdfd476d9b 100644 --- a/modules/juce_core/containers/juce_ListenerList.h +++ b/modules/juce_core/containers/juce_ListenerList.h @@ -73,10 +73,7 @@ namespace juce guaranteed that no more listeners will be called. By default a ListenerList is not thread safe. If thread-safety is required, - you can provide a thread-safe Array type as the second type parameter e.g. - @code - using ThreadSafeList = ListenerList>; - @endcode + use the ThreadSafeListenerList type. When calling listeners the iteration can be escaped early by using a "BailOutChecker". A BailOutChecker is a type that has a public member function @@ -87,8 +84,8 @@ namespace juce @tags{Core} */ -template > +template > class ListenerList { public: @@ -402,4 +399,13 @@ private: JUCE_DECLARE_NON_COPYABLE (ListenerList) }; +//============================================================================== +/** + A thread safe version of the ListenerList class. + + @see ListenerList +*/ +template +using ThreadSafeListenerList = ListenerList>; + } // namespace juce diff --git a/modules/juce_core/threads/juce_Thread.h b/modules/juce_core/threads/juce_Thread.h index 83407d0aba..9eef9a32eb 100644 --- a/modules/juce_core/threads/juce_Thread.h +++ b/modules/juce_core/threads/juce_Thread.h @@ -602,7 +602,7 @@ private: uint32 affinityMask = 0; bool deleteOnThreadEnd = false; std::atomic shouldExit { false }; - ListenerList> listeners; + ThreadSafeListenerList listeners; #if JUCE_ANDROID || JUCE_LINUX || JUCE_BSD std::atomic priority; diff --git a/modules/juce_core/threads/juce_ThreadPool.h b/modules/juce_core/threads/juce_ThreadPool.h index 5d94264040..ab4c2f9ae8 100644 --- a/modules/juce_core/threads/juce_ThreadPool.h +++ b/modules/juce_core/threads/juce_ThreadPool.h @@ -147,7 +147,7 @@ private: String jobName; ThreadPool* pool = nullptr; std::atomic shouldStop { false }, isActive { false }, shouldBeDeleted { false }; - ListenerList> listeners; + ThreadSafeListenerList listeners; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ThreadPoolJob) }; diff --git a/modules/juce_events/timers/juce_Timer.cpp b/modules/juce_events/timers/juce_Timer.cpp index 55aa2b068d..1557dbe18f 100644 --- a/modules/juce_events/timers/juce_Timer.cpp +++ b/modules/juce_events/timers/juce_Timer.cpp @@ -65,7 +65,7 @@ public: } private: - using ListenerListType = ListenerList>; + using ListenerListType = ThreadSafeListenerList; // By having a static ListenerList it can outlive the ShutdownDetector instance preventing // issues for objects trying to remove themselves after the instance has been deleted