EffectBase: Make callback getter/setter atomic
Plain sp<> not thread-safe for concurrent set and get.
Test: AudioEffectTest
Test: AudioPreProcessingTest
Test: BassBoostTest
Test: EnvReverbTest
Test: EqualizerTest
Test: LoudnessEnhancerTest
Test: PresetReverbTest
Test: VirtualizerTest
Test: VisualizerTest
Bug: 190024493
Change-Id: Ic65f8eabe21453aefefbdd0080e66d9cb7184f43
diff --git a/services/audioflinger/Effects.h b/services/audioflinger/Effects.h
index 9da95bc..661881e 100644
--- a/services/audioflinger/Effects.h
+++ b/services/audioflinger/Effects.h
@@ -138,8 +138,9 @@
int32_t __unused,
std::vector<uint8_t>* __unused) { return NO_ERROR; };
+ // mCallback is atomic so this can be lock-free.
void setCallback(const sp<EffectCallbackInterface>& callback) { mCallback = callback; }
- sp<EffectCallbackInterface>& callback() { return mCallback; }
+ sp<EffectCallbackInterface> getCallback() const { return mCallback.load(); }
status_t addHandle(EffectHandle *handle);
ssize_t disconnectHandle(EffectHandle *handle, bool unpinIfLast);
@@ -170,7 +171,7 @@
DISALLOW_COPY_AND_ASSIGN(EffectBase);
mutable Mutex mLock; // mutex for process, commands and handles list protection
- sp<EffectCallbackInterface> mCallback; // parent effect chain
+ mediautils::atomic_sp<EffectCallbackInterface> mCallback; // parent effect chain
const int mId; // this instance unique ID
const audio_session_t mSessionId; // audio session ID
const effect_descriptor_t mDescriptor;// effect descriptor received from effect engine