From 30873bfd08255e2c4e98ff5732ffff2838772617 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Wed, 31 Jul 2013 13:04:50 -0700 Subject: Unregister any handlers still registered on now "dead" ALoopers upon the death of an ALooper. Change-Id: I64c0835b8db04486204f3d0fa7173ee53708a116 related-to-bug: 10106648 --- media/libstagefright/foundation/ALooper.cpp | 4 ++++ media/libstagefright/foundation/ALooperRoster.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'media/libstagefright/foundation') diff --git a/media/libstagefright/foundation/ALooper.cpp b/media/libstagefright/foundation/ALooper.cpp index 22777a2..ebf9d8d 100644 --- a/media/libstagefright/foundation/ALooper.cpp +++ b/media/libstagefright/foundation/ALooper.cpp @@ -72,6 +72,10 @@ ALooper::ALooper() ALooper::~ALooper() { stop(); + + // Since this looper is "dead" (or as good as dead by now), + // have ALooperRoster unregister any handlers still registered for it. + gLooperRoster.unregisterStaleHandlers(); } void ALooper::setName(const char *name) { diff --git a/media/libstagefright/foundation/ALooperRoster.cpp b/media/libstagefright/foundation/ALooperRoster.cpp index ad10d2b..0c181ff 100644 --- a/media/libstagefright/foundation/ALooperRoster.cpp +++ b/media/libstagefright/foundation/ALooperRoster.cpp @@ -71,6 +71,20 @@ void ALooperRoster::unregisterHandler(ALooper::handler_id handlerID) { mHandlers.removeItemsAt(index); } +void ALooperRoster::unregisterStaleHandlers() { + Mutex::Autolock autoLock(mLock); + + for (size_t i = mHandlers.size(); i-- > 0;) { + const HandlerInfo &info = mHandlers.valueAt(i); + + sp looper = info.mLooper.promote(); + if (looper == NULL) { + ALOGV("Unregistering stale handler %d", mHandlers.keyAt(i)); + mHandlers.removeItemsAt(i); + } + } +} + status_t ALooperRoster::postMessage( const sp &msg, int64_t delayUs) { Mutex::Autolock autoLock(mLock); -- cgit v1.1