summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2011-12-13 11:47:54 -0800
committerGlenn Kasten <gkasten@google.com>2012-01-13 15:53:10 -0800
commit9806710f5d6722cfc5783c7eca3512451a0f2035 (patch)
treec0fb62e5d69389a3f31812a63ca90a76c7d6ab0e /services
parent09192653e836b21689f004bf8dee375356641181 (diff)
downloadframeworks_av-9806710f5d6722cfc5783c7eca3512451a0f2035.zip
frameworks_av-9806710f5d6722cfc5783c7eca3512451a0f2035.tar.gz
frameworks_av-9806710f5d6722cfc5783c7eca3512451a0f2035.tar.bz2
Fix locking for mMasterVolume and mMute
mMasterVolume and mMute are both protected by mutex in AudioFlinger class, but there were two places where they were accessed without a mutex. Also make AudioFlinger::mMasterMute private not protected. Change-Id: Ia3897daeb5c50313df5bcc071824357526237f3e
Diffstat (limited to 'services')
-rw-r--r--services/audioflinger/AudioFlinger.cpp12
-rw-r--r--services/audioflinger/AudioFlinger.h7
2 files changed, 15 insertions, 4 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 9fb666e..d267497 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -646,12 +646,14 @@ status_t AudioFlinger::setMasterMute(bool muted)
float AudioFlinger::masterVolume() const
{
- return mMasterVolume;
+ Mutex::Autolock _l(mLock);
+ return masterVolume_l();
}
bool AudioFlinger::masterMute() const
{
- return mMasterMute;
+ Mutex::Autolock _l(mLock);
+ return masterMute_l();
}
status_t AudioFlinger::setStreamVolume(int stream, float value, int output)
@@ -1379,8 +1381,10 @@ AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinge
readOutputParameters();
- mMasterVolume = mAudioFlinger->masterVolume();
- mMasterMute = mAudioFlinger->masterMute();
+ // Assumes constructor is called by AudioFlinger with it's mLock held,
+ // but it would be safer to explicitly pass these as parameters
+ mMasterVolume = mAudioFlinger->masterVolume_l();
+ mMasterMute = mAudioFlinger->masterMute_l();
for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) {
mStreamTypes[stream].volume = mAudioFlinger->streamVolumeInternal(stream);
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index f99e764..d22de26 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -765,7 +765,9 @@ private:
int16_t* mMixBuffer;
int mSuspended;
int mBytesWritten;
+ private:
bool mMasterMute;
+ protected:
SortedVector< wp<Track> > mActiveTracks;
virtual int getTrackName_l() = 0;
@@ -1388,6 +1390,8 @@ mutable Mutex mLock; // mutex for process, commands and handl
DefaultKeyedVector< int, sp<PlaybackThread> > mPlaybackThreads;
PlaybackThread::stream_type_t mStreamTypes[AUDIO_STREAM_CNT];
+
+ // both are protected by mLock
float mMasterVolume;
bool mMasterMute;
@@ -1399,6 +1403,9 @@ mutable Mutex mLock; // mutex for process, commands and handl
bool mBtNrecIsOff;
Vector<AudioSessionRef*> mAudioSessionRefs;
+
+ float masterVolume_l() const { return mMasterVolume; }
+ bool masterMute_l() const { return mMasterMute; }
};