From 17ef62cc1f9d092669af0fed465a9a77e0dc1a4f Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 25 Sep 2012 22:52:40 -0700 Subject: fix a possible dead-lock when clearing caches Bug: 7195815 Change-Id: I8e226b7ec445f9f4fe46ae216ef7cc41efc5a0fd --- libs/hwui/Caches.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'libs/hwui/Caches.cpp') diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index 4459495..f0f72f9 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -227,21 +227,29 @@ void Caches::clearGarbage() { textureCache.clearGarbage(); pathCache.clearGarbage(); - Mutex::Autolock _l(mGarbageLock); + Vector displayLists; + Vector layers; + + { // scope for the lock + Mutex::Autolock _l(mGarbageLock); + displayLists = mDisplayListGarbage; + layers = mLayerGarbage; + mDisplayListGarbage.clear(); + mLayerGarbage.clear(); + } - size_t count = mLayerGarbage.size(); + size_t count = displayLists.size(); for (size_t i = 0; i < count; i++) { - Layer* layer = mLayerGarbage.itemAt(i); - delete layer; + DisplayList* displayList = displayLists.itemAt(i); + delete displayList; } - mLayerGarbage.clear(); - count = mDisplayListGarbage.size(); + count = layers.size(); for (size_t i = 0; i < count; i++) { - DisplayList* displayList = mDisplayListGarbage.itemAt(i); - delete displayList; + Layer* layer = layers.itemAt(i); + delete layer; } - mDisplayListGarbage.clear(); + layers.clear(); } void Caches::deleteLayerDeferred(Layer* layer) { -- cgit v1.1