Browse Source

APVTS: Make adding/removing listeners threadsafe

tags/2021-05-28
reuk 5 years ago
parent
commit
e7004e634c
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 28 additions and 1 deletions
  1. +28
    -1
      modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.cpp

+ 28
- 1
modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.cpp View File

@@ -186,8 +186,35 @@ private:
parameter.setValueNotifyingHost (value);
}
class LockedListeners
{
public:
template <typename Fn>
void call (Fn&& fn)
{
const CriticalSection::ScopedLockType lock (mutex);
listeners.call (std::forward<Fn> (fn));
}
void add (Listener* l)
{
const CriticalSection::ScopedLockType lock (mutex);
listeners.add (l);
}
void remove (Listener* l)
{
const CriticalSection::ScopedLockType lock (mutex);
listeners.remove (l);
}
private:
CriticalSection mutex;
ListenerList<Listener> listeners;
};
RangedAudioParameter& parameter;
ListenerList<Listener> listeners;
LockedListeners listeners;
std::atomic<float> unnormalisedValue { 0.0f };
std::atomic<bool> needsUpdate { true }, listenersNeedCalling { true };
bool ignoreParameterChangedCallbacks { false };


Loading…
Cancel
Save