From 19a7c12ce19570e5a276bcc57f073882a536c436 Mon Sep 17 00:00:00 2001 From: Dominggoes Isakh Date: Sun, 30 Dec 2018 00:00:47 +0100 Subject: [PATCH] gralloc: Clone handle when unregistering buffer in separate thread Change-Id: I113158592e29867246cdfd1daa96a3960d6851d6 --- exynos4/hal/libgralloc_ump/gralloc_module.cpp | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/exynos4/hal/libgralloc_ump/gralloc_module.cpp b/exynos4/hal/libgralloc_ump/gralloc_module.cpp index 1761019..1079785 100644 --- a/exynos4/hal/libgralloc_ump/gralloc_module.cpp +++ b/exynos4/hal/libgralloc_ump/gralloc_module.cpp @@ -607,9 +607,42 @@ void* gralloc_unregister_buffer_thread(void *data) { usleep(1000000); // 1000ms unregister_buffer(hnd); ALOGD_IF(debug_level > 1, "%s: ump_id:%d END", __func__, hnd->ump_id); + delete hnd; return NULL; } +static private_handle_t* clone_private_handle(private_handle_t* hnd) { + private_handle_t* result = new private_handle_t( + hnd->flags, + hnd->size, + hnd->base, + hnd->lockState, + (ump_secure_id)hnd->ump_id, + (ump_handle)hnd->ump_mem_handle, + hnd->fd, + hnd->offset, + hnd->paddr); + result->magic = hnd->magic; + result->base = hnd->base; + result->writeOwner = hnd->writeOwner; + result->pid = hnd->pid; + result->format = hnd->format; + result->usage = hnd->usage; + result->width = hnd->width; + result->height = hnd->height; + result->bpp = hnd->bpp; + result->stride = hnd->stride; + result->yaddr = hnd->yaddr; + result->uoffset = hnd->uoffset; + result->voffset = hnd->voffset; + result->ion_client = hnd->ion_client; + result->ion_memory = hnd->ion_memory; + result->backing_store = hnd->backing_store; + result->producer_usage = hnd->producer_usage; + result->consumer_usage = hnd->consumer_usage; + return result; +} + static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_handle_t handle) { if (private_handle_t::validate(handle) < 0) { @@ -626,7 +659,7 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_hand pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); int rc = pthread_create(&unreg_buffer_thread, &thread_attr, - gralloc_unregister_buffer_thread, (void *) handle); + gralloc_unregister_buffer_thread, (void *) clone_private_handle(hnd)); if (rc < 0) { ALOGE("%s: Unable to create thread", __func__); return -1;