From ab7f01d51b9dbb031bddaa10f32b070942cd57e0 Mon Sep 17 00:00:00 2001 From: Xiaohui Chen Date: Tue, 7 Apr 2015 10:12:24 -0700 Subject: [PATCH] fix a potential race condition Currently worker threads in computeBestConfiguration may NOT completely finish before timeout. But the code will start using the result while the worker threads are still working on the same object. This may cause exceptions. b/19966623 Change-Id: I62ffcb796d648891ee339b6a978f575ebad8352b --- .../java/com/android/server/AssetAtlasService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java index f10666749981b..66cc29ad3795b 100644 --- a/services/core/java/com/android/server/AssetAtlasService.java +++ b/services/core/java/com/android/server/AssetAtlasService.java @@ -415,12 +415,20 @@ public class AssetAtlasService extends IAssetAtlas.Stub { new Thread(worker, "Atlas Worker #" + (i + 1)).start(); } + boolean isAllWorkerFinished; try { - signal.await(10, TimeUnit.SECONDS); + isAllWorkerFinished = signal.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Log.w(LOG_TAG, "Could not complete configuration computation"); return null; } + + if (!isAllWorkerFinished) { + // We have to abort here, otherwise the async updates on "results" would crash the + // sort later. + Log.w(LOG_TAG, "Could not complete configuration computation before timeout."); + return null; + } } // Maximize the number of packed bitmaps, minimize the texture size