gralloc: Allow unmapping concurrent handles
authorRicardo Cerqueira <cyanogenmod@cerqueira.org>
Sun, 27 Oct 2013 19:51:25 +0000 (19:51 +0000)
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>
Sun, 27 Oct 2013 19:51:25 +0000 (19:51 +0000)
If we allow registering those buffers, we need to let them go, too

Change-Id: I6c2dc862e1e783e2b0d3c7d37d60ebe2290173fa

exynos4/hal/libgralloc_ump/gralloc_module.cpp

index 3bbb8319cc13d1a751dee482ffb4621c663813d8..79c4750f4d3d5015e56da436e3e040b2e695359a 100644 (file)
@@ -318,43 +318,40 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_hand
     ALOGE_IF(hnd->lockState & private_handle_t::LOCK_STATE_READ_MASK,
             "[unregister] handle %p still locked (state=%08x)", hnd, hnd->lockState);
 
-    /* never unmap buffers that were created in this process */
-    if (hnd->pid != getpid()) {
-        pthread_mutex_lock(&s_map_lock);
-        if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) {
-            ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
-            hnd->base = 0;
-            ump_reference_release((ump_handle)hnd->ump_mem_handle);
-            hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
-            hnd->lockState  = 0;
-            hnd->writeOwner = 0;
-        } else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_IOCTL) {
-            if(hnd->base != 0)
-                gralloc_unmap(module, handle);
-
-            pthread_mutex_unlock(&s_map_lock);
-            if (0 < gMemfd) {
-                close(gMemfd);
-                gMemfd = 0;
-            }
-            return 0;
-        } else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
-            ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
-            ump_reference_release((ump_handle)hnd->ump_mem_handle);
-            if (hnd->base)
-                gralloc_unmap(module, handle);
-
-            hnd->base = 0;
-            hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
-            hnd->lockState  = 0;
-            hnd->writeOwner = 0;
-        } else {
-            ALOGE("unregistering non-UMP buffer not supported");
-        }
+    pthread_mutex_lock(&s_map_lock);
+    if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) {
+        ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
+        hnd->base = 0;
+        ump_reference_release((ump_handle)hnd->ump_mem_handle);
+        hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
+        hnd->lockState  = 0;
+        hnd->writeOwner = 0;
+    } else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_IOCTL) {
+        if(hnd->base != 0)
+            gralloc_unmap(module, handle);
 
         pthread_mutex_unlock(&s_map_lock);
+        if (0 < gMemfd) {
+            close(gMemfd);
+            gMemfd = 0;
+        }
+        return 0;
+    } else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
+        ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
+        ump_reference_release((ump_handle)hnd->ump_mem_handle);
+        if (hnd->base)
+            gralloc_unmap(module, handle);
+
+        hnd->base = 0;
+        hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
+        hnd->lockState  = 0;
+        hnd->writeOwner = 0;
+    } else {
+        ALOGE("unregistering non-UMP buffer not supported");
     }
 
+    pthread_mutex_unlock(&s_map_lock);
+
     return 0;
 }