Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94dfbb4f authored by Andy Hung's avatar Andy Hung
Browse files

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
parent e3f46d5b
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -2090,7 +2090,8 @@ void AudioFlinger::removeNotificationClient(pid_t pid)
    }
}

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 @@ status_t AudioFlinger::openOutput(const media::OpenOutputRequest& request,
            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 @@ status_t AudioFlinger::openOutput(const media::OpenOutputRequest& request,
                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 @@ audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1,
    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 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output)
            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 @@ status_t AudioFlinger::openInput(const media::OpenInputRequest& request,

    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 @@ status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input)
            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 @@ DeviceTypeSet AudioFlinger::primaryOutputDevice_l() const
        return {};
    }

    return thread->outDeviceTypes();
    audio_utils::lock_guard l(thread->mutex());
    return thread->outDeviceTypes_l();
}

IAfPlaybackThread* AudioFlinger::fastPlaybackThread_l() const
@@ -4487,8 +4489,9 @@ bool AudioFlinger::isNonOffloadableGlobalEffectEnabled_l() const
    }

    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;
        }
+4 −2
Original line number Diff line number Diff line
@@ -342,7 +342,8 @@ private:

    // ----- begin IAfThreadCallback interface

    bool isNonOffloadableGlobalEffectEnabled_l() const final REQUIRES(mutex());
    bool isNonOffloadableGlobalEffectEnabled_l() const final
            REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex;
    bool btNrecIsOff() const final { return mBtNrecIsOff.load(); }
    float masterVolume_l() const final REQUIRES(mutex());
    bool masterMute_l() const final REQUIRES(mutex());
@@ -387,7 +388,8 @@ private:
            const audioflinger::SyncEventCallback& callBack,
            const wp<IAfTrackBase>& cookie) final EXCLUDES_AudioFlinger_Mutex;

    void ioConfigChanged(audio_io_config_event_t event,
    // Hold either AudioFlinger::mutex or ThreadBase::mutex
    void ioConfigChanged_l(audio_io_config_event_t event,
            const sp<AudioIoDescriptor>& ioDesc,
            pid_t pid = 0) final EXCLUDES_AudioFlinger_ClientMutex;
    void onNonOffloadableGlobalEffectEnable() final EXCLUDES_AudioFlinger_Mutex;
+8 −2
Original line number Diff line number Diff line
@@ -3084,7 +3084,10 @@ uint32_t EffectChain::EffectCallback::sampleRate() const {
    return t->sampleRate();
}

audio_channel_mask_t EffectChain::EffectCallback::inChannelMask(int id) const {
audio_channel_mask_t EffectChain::EffectCallback::inChannelMask(int id) const
NO_THREAD_SAFETY_ANALYSIS
// calling function 'hasAudioSession_l' requires holding mutex 'ThreadBase_Mutex' exclusively
{
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return AUDIO_CHANNEL_NONE;
@@ -3120,7 +3123,10 @@ uint32_t EffectChain::EffectCallback::inChannelCount(int id) const {
    return audio_channel_count_from_out_mask(inChannelMask(id));
}

audio_channel_mask_t EffectChain::EffectCallback::outChannelMask() const {
audio_channel_mask_t EffectChain::EffectCallback::outChannelMask() const
NO_THREAD_SAFETY_ANALYSIS
// calling function 'hasAudioSession_l' requires holding mutex 'ThreadBase_Mutex' exclusively
{
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return AUDIO_CHANNEL_NONE;
+3 −1
Original line number Diff line number Diff line
@@ -488,8 +488,10 @@ public:
    bool isBitPerfectCompatible() const final;

    // isCompatibleWithThread_l() must be called with thread->mutex() held
    bool isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const final;
    bool isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const final
            REQUIRES(audio_utils::ThreadBase_Mutex);

    // Requires either IAfThreadBase::mutex() or EffectChain::mutex() held
    bool containsHapticGeneratingEffect_l() final;

    void setHapticIntensity_l(int id, os::HapticScale intensity) final;
+168 −112

File changed.

Preview size limit exceeded, changes collapsed.

Loading