Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ThreadSafeBlockingListenerList #1451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions modules/juce_core/containers/juce_ListenerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace juce
@tags{Core}
*/
template <typename ListenerClass,
typename ArrayType = Array<ListenerClass*>>
typename ArrayType = Array<ListenerClass*>,
typename LockMode = ScopedTryLock>
class ListenerList
{
public:
Expand Down Expand Up @@ -230,13 +231,16 @@ class ListenerList
Callback&& callback)
{
#if JUCE_ASSERTIONS_ENABLED_OR_LOGGED
const ScopedTryLock callCheckedExcludingLock (*callCheckedExcludingMutex);
const LockMode callCheckedExcludingLock (*callCheckedExcludingMutex);

// If you hit this assertion it means you're trying to call the listeners from multiple
// threads concurrently. If you need to do this either use a LightweightListenerList, for a
// lock free option, or a ThreadSafeListenerList if you also need the extra guarantees
// provided by ListenerList. See the class descriptions for more details.
jassert (callCheckedExcludingLock.isLocked());
if (std::is_same<ScopedTryLock, LockMode>())
{
jassert(((const ScopedTryLock*)&callCheckedExcludingLock)->isLocked());
}
#endif

if (! initialised())
Expand Down Expand Up @@ -415,6 +419,9 @@ class ListenerList
*/
template <typename ListenerClass>
using ThreadSafeListenerList = ListenerList<ListenerClass, Array<ListenerClass*, CriticalSection>>;
template <typename ListenerClass>
using ThreadSafeBlockingListenerList = ListenerList<ListenerClass, Array<ListenerClass*, CriticalSection>, ScopedLock>;


//==============================================================================
/**
Expand Down