Thread: Add safety annotations for methods
First pass.
Test: atest AudioTrackTest AudioRecordTest
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioPlaybackCaptureTest
Test: Camera YouTube
Bug: 275748373
Merged-In: I7245f0657e54f2230703febfef67fb2acfdc1b5a
Change-Id: I7245f0657e54f2230703febfef67fb2acfdc1b5a
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 29c6845..1a47fce 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2090,7 +2090,8 @@
}
}
-void AudioFlinger::ioConfigChanged(audio_io_config_event_t event,
+// Hold either AudioFlinger::mutex or ThreadBase::mutex
+void AudioFlinger::ioConfigChanged_l(audio_io_config_event_t event,
const sp<AudioIoDescriptor>& ioDesc,
pid_t pid) {
media::AudioIoConfigEvent eventAidl = VALUE_OR_FATAL(
@@ -2944,7 +2945,7 @@
latencyMs = playbackThread->latency();
// notify client processes of the new output creation
- playbackThread->ioConfigChanged(AUDIO_OUTPUT_OPENED);
+ playbackThread->ioConfigChanged_l(AUDIO_OUTPUT_OPENED);
// the first primary output opened designates the primary hw device if no HW module
// named "primary" was already loaded.
@@ -2958,7 +2959,7 @@
mHardwareStatus = AUDIO_HW_IDLE;
}
} else {
- thread->ioConfigChanged(AUDIO_OUTPUT_OPENED);
+ thread->ioConfigChanged_l(AUDIO_OUTPUT_OPENED);
}
response->output = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
response->config = VALUE_OR_RETURN_STATUS(
@@ -2991,7 +2992,7 @@
thread->addOutputTrack(thread2);
mPlaybackThreads.add(id, thread);
// notify client processes of the new output creation
- thread->ioConfigChanged(AUDIO_OUTPUT_OPENED);
+ thread->ioConfigChanged_l(AUDIO_OUTPUT_OPENED);
return id;
}
@@ -3051,7 +3052,7 @@
mMmapThreads.removeItem(output);
ALOGD("closing mmapThread %p", mmapThread.get());
}
- ioConfigChanged(AUDIO_OUTPUT_CLOSED, sp<AudioIoDescriptor>::make(output));
+ ioConfigChanged_l(AUDIO_OUTPUT_CLOSED, sp<AudioIoDescriptor>::make(output));
mPatchPanel->notifyStreamClosed(output);
}
// The thread entity (active unit of execution) is no longer running here,
@@ -3154,7 +3155,7 @@
if (thread != 0) {
// notify client processes of the new input creation
- thread->ioConfigChanged(AUDIO_INPUT_OPENED);
+ thread->ioConfigChanged_l(AUDIO_INPUT_OPENED);
return NO_ERROR;
}
return NO_INIT;
@@ -3313,7 +3314,7 @@
dumpToThreadLog_l(mmapThread);
mMmapThreads.removeItem(input);
}
- ioConfigChanged(AUDIO_INPUT_CLOSED, sp<AudioIoDescriptor>::make(input));
+ ioConfigChanged_l(AUDIO_INPUT_CLOSED, sp<AudioIoDescriptor>::make(input));
}
// FIXME: calling thread->exit() without mutex() held should not be needed anymore now that
// we have a different lock for notification client
@@ -3693,7 +3694,8 @@
return {};
}
- return thread->outDeviceTypes();
+ audio_utils::lock_guard l(thread->mutex());
+ return thread->outDeviceTypes_l();
}
IAfPlaybackThread* AudioFlinger::fastPlaybackThread_l() const
@@ -4487,8 +4489,9 @@
}
for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
- sp<IAfEffectChain> ec =
- mPlaybackThreads.valueAt(i)->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX);
+ const auto thread = mPlaybackThreads.valueAt(i);
+ audio_utils::lock_guard l(thread->mutex());
+ const sp<IAfEffectChain> ec = thread->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX);
if (ec != 0 && ec->isNonOffloadableEnabled()) {
return true;
}