Skip to content

Commit 91540ae

Browse files
committed
Fix theoretical race condition in addOutputTrack
This is not a real race, because addOutputTrack was only called in two places, and in both places there could be no other threads referencing the DuplicatingThread instance. Those two places are: - the DuplicatingThread constructor, which is of course safe - openDuplicateOutput - this is safe because it's called immediately after the new DuplicatingThread, and there are no sp<> either in the constructor or here which could cause onFirstRef() to do Thread::run(). But for safety in case addOutputTrack is ever called somewhere else, or there are sp<> created earlier, it is safer to take the thread lock. Change-Id: I1502d014fa37ec5dbf4bf40d3e2884af311cd5e9
1 parent be3835c commit 91540ae

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,6 +3229,7 @@ bool AudioFlinger::DuplicatingThread::threadLoop()
32293229

32303230
void AudioFlinger::DuplicatingThread::addOutputTrack(MixerThread *thread)
32313231
{
3232+
Mutex::Autolock _l(mLock);
32323233
// FIXME explain this formula
32333234
int frameCount = (3 * mFrameCount * mSampleRate) / thread->sampleRate();
32343235
OutputTrack *outputTrack = new OutputTrack(thread,

0 commit comments

Comments
 (0)