AudioFlinger: improve purgeStaleEffects_l thread-safety

There was a situation when a thread in audioserver
called ThreadBase::disconnectEffectHandle that would
remove effect chain objects from system in the same
time that purgeStaleEffects_l would do effect chain
discovery. This caused race conditions and crash
in purgeStaleEffects_l.

This patch fixes that by putting code that handles
discovery of effect chains in playback and record threads
under mutex of currently checked ThreadBase. This
ensures that any other thread that currently removes
effect objects from system finishes before
purgeStaleEffects_l proceeds with effect discovery.

Bug: 65535528
Test: Check Audio Effects works correctly.
Change-Id: Ia7daac6aaf16c4099ef569e3d438197ac7aad5d4
1 file changed