diff options
| author | Glenn Kasten <gkasten@google.com> | 2012-11-08 10:04:06 -0800 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-11-08 10:04:07 -0800 |
| commit | 755e8e1dcf36f282b727ff22d87d3c2fac70d30a (patch) | |
| tree | e0c8468a87427f51deba8d018931afb4394b3f1d | |
| parent | 864585df53eb97c31e77b3ad7c0d89e4f9b42588 (diff) | |
| parent | d5ed6e88a9bea1879e41d7defaf1edea7c09f554 (diff) | |
| download | frameworks_av-755e8e1dcf36f282b727ff22d87d3c2fac70d30a.zip frameworks_av-755e8e1dcf36f282b727ff22d87d3c2fac70d30a.tar.gz frameworks_av-755e8e1dcf36f282b727ff22d87d3c2fac70d30a.tar.bz2 | |
Merge "Fix call to restoreTrack_l() without lock held"
| -rw-r--r-- | include/media/AudioTrack.h | 7 | ||||
| -rw-r--r-- | media/libmedia/AudioTrack.cpp | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h index 529f74e..1a19999 100644 --- a/include/media/AudioTrack.h +++ b/include/media/AudioTrack.h @@ -481,6 +481,7 @@ protected: // body of AudioTrackThread::threadLoop() bool processAudioBuffer(const sp<AudioTrackThread>& thread); + // caller must hold lock on mLock for all _l methods status_t createTrack_l(audio_stream_type_t streamType, uint32_t sampleRate, audio_format_t format, @@ -535,7 +536,13 @@ protected: audio_output_flags_t mFlags; int mSessionId; int mAuxEffectId; + + // When locking both mLock and mCblk->lock, must lock in this order to avoid deadlock: + // 1. mLock + // 2. mCblk->lock + // It is OK to lock only mCblk->lock. mutable Mutex mLock; + status_t mRestoreStatus; bool mIsTimed; int mPreviousPriority; // before start() diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index f55ec9a..f7921ba 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -1121,8 +1121,14 @@ TimedAudioTrack::TimedAudioTrack() { status_t TimedAudioTrack::allocateTimedBuffer(size_t size, sp<IMemory>* buffer) { + AutoMutex lock(mLock); status_t result = UNKNOWN_ERROR; + // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed + // while we are accessing the cblk + sp<IAudioTrack> audioTrack = mAudioTrack; + sp<IMemory> iMem = mCblkMemory; + // If the track is not invalid already, try to allocate a buffer. alloc // fails indicating that the server is dead, flag the track as invalid so // we can attempt to restore in just a bit. |
