From d6ffef4cef30a0ab8282f5c9b79f2ae8d5793f05 Mon Sep 17 00:00:00 2001 From: Naseer Ahmed Date: Mon, 23 Apr 2012 17:28:27 -0400 Subject: [PATCH] gralloc: Add locking to alloc and free in ION Change-Id: I16e24e3d366b15a458b19983827233a7bd27d9f7 (cherry picked from commit edad58e17deb0cb1d9ff4754fbac511eea8e4ecf) --- libgralloc/gpu.cpp | 2 +- libgralloc/ionalloc.cpp | 2 ++ libgralloc/ionalloc.h | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp index 18f810f..a05ae4a 100755 --- a/libgralloc/gpu.cpp +++ b/libgralloc/gpu.cpp @@ -264,12 +264,12 @@ int gpu_context_t::free_impl(private_handle_t const* hnd) { int index = (hnd->base - m->framebuffer->base) / bufferSize; m->bufferMask &= ~(1<base, const_cast(hnd)); sp memalloc = mAllocCtrl->getAllocator(hnd->flags); int err = memalloc->free_buffer((void*)hnd->base, (size_t) hnd->size, hnd->offset, hnd->fd); if(err) return err; - terminateBuffer(&m->base, const_cast(hnd)); } // Release the genlock diff --git a/libgralloc/ionalloc.cpp b/libgralloc/ionalloc.cpp index 94a27e3..a04a6b7 100644 --- a/libgralloc/ionalloc.cpp +++ b/libgralloc/ionalloc.cpp @@ -64,6 +64,7 @@ void IonAlloc::close_device() int IonAlloc::alloc_buffer(alloc_data& data) { + Locker::Autolock _l(mLock); int err = 0; int ionSyncFd = FD_INIT; int iFd = FD_INIT; @@ -151,6 +152,7 @@ int IonAlloc::alloc_buffer(alloc_data& data) int IonAlloc::free_buffer(void* base, size_t size, int offset, int fd) { + Locker::Autolock _l(mLock); LOGD("ion: Freeing buffer base:%p size:%d fd:%d", base, size, fd); int err = 0; diff --git a/libgralloc/ionalloc.h b/libgralloc/ionalloc.h index 91a1d65..27e5e01 100644 --- a/libgralloc/ionalloc.h +++ b/libgralloc/ionalloc.h @@ -31,6 +31,7 @@ #define GRALLOC_IONALLOC_H #include "memalloc.h" +#include "gr.h" #include namespace gralloc { @@ -63,6 +64,8 @@ namespace gralloc { void close_device(); + mutable Locker mLock; + }; }