diff options
author | Rob Clark <robdclark@gmail.com> | 2015-08-31 13:31:15 -0400 |
---|---|---|
committer | Chih-Wei Huang <cwhuang@linux.org.tw> | 2016-03-17 18:43:47 +0800 |
commit | 579e33549dc2293bf16b5571483bac2d36567318 (patch) | |
tree | 251ad899654388179dfc3c7159d1a215ce0d1e8f | |
parent | aac8ca7e1bd5b76967ec9e322526bdb1df10e3d7 (diff) | |
download | external_drm_gralloc-579e33549dc2293bf16b5571483bac2d36567318.zip external_drm_gralloc-579e33549dc2293bf16b5571483bac2d36567318.tar.gz external_drm_gralloc-579e33549dc2293bf16b5571483bac2d36567318.tar.bz2 |
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.c | 70 |
1 files changed, 55 insertions, 15 deletions
@@ -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) |