summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gralloc.c70
1 files changed, 55 insertions, 15 deletions
diff --git a/gralloc.c b/gralloc.c
index 92866ca..b338ab9 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,25 +141,40 @@ 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);
+
bo = gralloc_drm_bo_from_handle(handle);
- if (!bo)
- return -EINVAL;
+ if (!bo) {
+ err = -EINVAL;
+ goto unlock;
+ }
- return gralloc_drm_bo_lock(bo, usage, x, y, w, h, ptr);
+ err = 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);
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)
@@ -163,14 +190,21 @@ 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);
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,
@@ -179,15 +213,19 @@ 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);
@@ -202,7 +240,9 @@ static int drm_mod_alloc_gpu0(alloc_device_t *dev,
/* in pixels */
*stride /= bpp;
- 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)