From 021cf9634ab09c0753a40b7c9ef4ba603be5c3da Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Tue, 13 May 2014 10:18:14 -0700 Subject: AudioFlinger: add specific mutex for client lists Add a specific mutex to protect access to mClients and mNotificationClients lists. This avoids locking the main AudioFlinger mutex from inside thread loops and allows not to worry about cross deadlocks when sending a config event with status reply while keeping the ThreadBase or AudioFlinger mutex locked. As a way of consequence, remove notification client list passed to processConfigEvents_l() and audioConfigChanged() as the list can now be accessed by locking client mutex only. Change-Id: I228022204b6709a8bb60cc96d9514a6ffe59b62e --- services/audioflinger/AudioFlinger.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'services/audioflinger/AudioFlinger.h') diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 894bd35..c1d4c08 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -453,11 +453,7 @@ private: // no range check, doesn't check per-thread stream volume, AudioFlinger::mLock held float streamVolume_l(audio_stream_type_t stream) const { return mStreamTypes[stream].volume; } - void audioConfigChanged_l(const DefaultKeyedVector< pid_t,sp >& - notificationClients, - int event, - audio_io_handle_t ioHandle, - const void *param2); + void audioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2); // Allocate an audio_io_handle_t, session ID, effect ID, or audio_module_handle_t. // They all share the same ID space, but the namespaces are actually independent @@ -482,8 +478,6 @@ private: void removeClient_l(pid_t pid); void removeNotificationClient(pid_t pid); - DefaultKeyedVector< pid_t,sp > notificationClients() { - Mutex::Autolock _l(mLock); return mNotificationClients; } bool isNonOffloadableGlobalEffectEnabled_l(); void onNonOffloadableGlobalEffectEnable(); @@ -553,7 +547,11 @@ private: }; mutable Mutex mLock; - + // protects mClients and mNotificationClients. + // must be locked after mLock and ThreadBase::mLock if both must be locked + // avoids acquiring AudioFlinger::mLock from inside thread loop. + mutable Mutex mClientLock; + // protected by mClientLock DefaultKeyedVector< pid_t, wp > mClients; // see ~Client() mutable Mutex mHardwareLock; @@ -602,6 +600,7 @@ private: DefaultKeyedVector< audio_io_handle_t, sp > mRecordThreads; + // protected by mClientLock DefaultKeyedVector< pid_t, sp > mNotificationClients; volatile int32_t mNextUniqueId; // updated by android_atomic_inc @@ -622,7 +621,7 @@ private: // to be created private: - sp registerPid_l(pid_t pid); // always returns non-0 + sp registerPid(pid_t pid); // always returns non-0 // for use from destructor status_t closeOutput_nonvirtual(audio_io_handle_t output); -- cgit v1.1