summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@gmail.com>2015-08-31 13:31:15 -0400
committerRob Clark <robdclark@gmail.com>2015-08-31 13:31:18 -0400
commit928e9f88a171defb71c21bbc530971c09dbbac6b (patch)
treec99ad80b88ebfea00f41c121a0b9f99c78b4ff0c
parent6914669c58339be9bad6ecdda41d3a2f986b00ae (diff)
downloaddrm_gralloc-928e9f88a171defb71c21bbc530971c09dbbac6b.tar.gz
WIP: synchronize gralloc entry points
Note entirely sure what synchronization guarantees android provides before calling in to module.. but stuff inside gralloc module is definately not thread-safe so slap a big lock around the outside.
-rw-r--r--gralloc.c86
1 files changed, 67 insertions, 19 deletions
diff --git a/gralloc.c b/gralloc.c
index 4902d0b..7ebfb82 100644
--- a/gralloc.c
+++ b/gralloc.c
@@ -32,6 +32,8 @@
#include "gralloc_drm.h"
#include "gralloc_drm_priv.h"
+static pthread_mutex_t gralloc_lock = PTHREAD_MUTEX_INITIALIZER;
+
/*
* Initialize the DRM device object, optionally with KMS.
*/
@@ -114,13 +116,23 @@ static int drm_mod_register_buffer(const gralloc_module_t *mod,
if (err)
return err;
- return gralloc_drm_handle_register(handle, dmod->drm);
+ pthread_mutex_lock(&gralloc_lock);
+ err = gralloc_drm_handle_register(handle, dmod->drm);
+ pthread_mutex_unlock(&gralloc_lock);
+
+ return err;
}
static int drm_mod_unregister_buffer(const gralloc_module_t *mod,
buffer_handle_t handle)
{
- return gralloc_drm_handle_unregister(handle);
+ int err;
+
+ pthread_mutex_lock(&gralloc_lock);
+ err = gralloc_drm_handle_unregister(handle);
+ pthread_mutex_unlock(&gralloc_lock);
+
+ return err;
}
static int drm_mod_lock(const gralloc_module_t *mod, buffer_handle_t handle,
@@ -129,29 +141,44 @@ static int drm_mod_lock(const gralloc_module_t *mod, buffer_handle_t handle,
struct gralloc_drm_bo_t *bo;
int err;
+ pthread_mutex_lock(&gralloc_lock);
+
LOGHDL(gralloc_drm_handle(handle));
bo = gralloc_drm_bo_from_handle(handle);
- if (!bo)
- return -EINVAL;
+ if (!bo) {
+ err = -EINVAL;
+ goto unlock;
+ }
+
+ err = gralloc_drm_bo_lock(bo, usage, x, y, w, h, ptr);
- return gralloc_drm_bo_lock(bo, usage, x, y, w, h, ptr);
+unlock:
+ pthread_mutex_unlock(&gralloc_lock);
+ return err;
}
static int drm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle)
{
struct drm_module_t *dmod = (struct drm_module_t *) mod;
struct gralloc_drm_bo_t *bo;
+ int err = 0;
+
+ pthread_mutex_lock(&gralloc_lock);
LOGHDL(gralloc_drm_handle(handle));
bo = gralloc_drm_bo_from_handle(handle);
- if (!bo)
- return -EINVAL;
+ if (!bo) {
+ err = -EINVAL;
+ goto unlock;
+ }
gralloc_drm_bo_unlock(bo);
- return 0;
+unlock:
+ pthread_mutex_unlock(&gralloc_lock);
+ return err;
}
static int drm_mod_close_gpu0(struct hw_device_t *dev)
@@ -167,16 +194,23 @@ static int drm_mod_free_gpu0(alloc_device_t *dev, buffer_handle_t handle)
{
struct drm_module_t *dmod = (struct drm_module_t *) dev->common.module;
struct gralloc_drm_bo_t *bo;
+ int err = 0;
+
+ pthread_mutex_lock(&gralloc_lock);
LOGHDL(gralloc_drm_handle(handle));
bo = gralloc_drm_bo_from_handle(handle);
- if (!bo)
- return -EINVAL;
+ if (!bo) {
+ err = -EINVAL;
+ goto unlock;
+ }
gralloc_drm_bo_decref(bo);
- return 0;
+unlock:
+ pthread_mutex_unlock(&gralloc_lock);
+ return err;
}
static int drm_mod_alloc_gpu0(alloc_device_t *dev,
@@ -185,22 +219,26 @@ static int drm_mod_alloc_gpu0(alloc_device_t *dev,
{
struct drm_module_t *dmod = (struct drm_module_t *) dev->common.module;
struct gralloc_drm_bo_t *bo;
- int size, bpp, err;
+ int size, bpp, err = 0;
bpp = gralloc_drm_get_bpp(format);
if (!bpp)
return -EINVAL;
+ pthread_mutex_lock(&gralloc_lock);
+
bo = gralloc_drm_bo_create(dmod->drm, w, h, format, usage);
- if (!bo)
- return -ENOMEM;
+ if (!bo) {
+ err = -ENOMEM;
+ goto unlock;
+ }
if (gralloc_drm_bo_need_fb(bo)) {
err = gralloc_drm_bo_add_fb(bo);
if (err) {
ALOGE("failed to add fb");
gralloc_drm_bo_decref(bo);
- return err;
+ goto unlock;
}
}
@@ -210,7 +248,9 @@ static int drm_mod_alloc_gpu0(alloc_device_t *dev,
LOGHDL(gralloc_drm_handle(*handle));
- return 0;
+unlock:
+ pthread_mutex_unlock(&gralloc_lock);
+ return err;
}
static int drm_mod_open_gpu0(struct drm_module_t *dmod, hw_device_t **dev)
@@ -261,14 +301,22 @@ static int drm_mod_post_fb0(struct framebuffer_device_t *fb,
{
struct drm_module_t *dmod = (struct drm_module_t *) fb->common.module;
struct gralloc_drm_bo_t *bo;
+ int err;
+
+ pthread_mutex_lock(&gralloc_lock);
LOGHDL(gralloc_drm_handle(handle));
bo = gralloc_drm_bo_from_handle(handle);
- if (!bo)
- return -EINVAL;
+ if (!bo) {
+ err = -EINVAL;
+ goto unlock;
+ }
- return gralloc_drm_bo_post(bo);
+ err = gralloc_drm_bo_post(bo);
+unlock:
+ pthread_mutex_unlock(&gralloc_lock);
+ return err;
}
#include <GLES/gl.h>