From 0d11baf88920660cf0e30b25b7268a9459e8ffa5 Mon Sep 17 00:00:00 2001 From: Kobi Cohen Arazi Date: Fri, 15 Apr 2011 10:38:33 -0700 Subject: [PATCH] Add lock before calling initEglImage Without that lock, there is a chance of race condition where while composing a specific index, requestBuf with the same index can be executed and touch the same data that is being used in initEglImage. (e.g. dirty flag in texture) --- services/surfaceflinger/Layer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index c9dcef370..dfee803bd 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -874,8 +874,16 @@ status_t Layer::BufferManager::initEglImage(EGLDisplay dpy, ssize_t index = mActiveBuffer; if (index >= 0) { if (!mFailover) { - Image& texture(mBufferData[index].texture); - err = mTextureManager.initEglImage(&texture, dpy, buffer); + { + // Without that lock, there is a chance of race condition + // where while composing a specific index, requestBuf + // with the same index can be executed and touch the same data + // that is being used in initEglImage. + // (e.g. dirty flag in texture) + Mutex::Autolock _l(mLock); + Image& texture(mBufferData[index].texture); + err = mTextureManager.initEglImage(&texture, dpy, buffer); + } // if EGLImage fails, we switch to regular texture mode, and we // free all resources associated with using EGLImages. if (err == NO_ERROR) {