Mesa (master): drm-shim: move handle lock to shim_fd

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 30 08:54:40 UTC 2020


Module: Mesa
Branch: master
Commit: 6b34c8d35f5c8cf8febc1310012de67e6f41b09f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6b34c8d35f5c8cf8febc1310012de67e6f41b09f

Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date:   Sat Apr 25 12:23:39 2020 +0300

drm-shim: move handle lock to shim_fd

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Acked-by: Matt Turner <mattst88 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4594>

---

 src/drm-shim/device.c   | 18 +++++++++---------
 src/drm-shim/drm_shim.h |  3 +++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/drm-shim/device.c b/src/drm-shim/device.c
index f3f0e53347b..39a7c2107ef 100644
--- a/src/drm-shim/device.c
+++ b/src/drm-shim/device.c
@@ -42,7 +42,6 @@
 #include "util/hash_table.h"
 #include "util/u_atomic.h"
 
-static mtx_t handle_lock = _MTX_INITIALIZER_NP;
 
 #ifndef HAVE_MEMFD_CREATE
 #include <sys/syscall.h>
@@ -89,6 +88,7 @@ drm_shim_file_create(int fd)
    struct shim_fd *shim_fd = calloc(1, sizeof(*shim_fd));
 
    shim_fd->fd = fd;
+   mtx_init(&shim_fd->handle_lock, mtx_plain);
    shim_fd->handles = _mesa_hash_table_create(NULL,
                                               uint_key_hash,
                                               uint_key_compare);
@@ -174,18 +174,18 @@ drm_shim_ioctl_gem_close(int fd, unsigned long request, void *arg)
    if (!c->handle)
       return 0;
 
-   mtx_lock(&handle_lock);
+   mtx_lock(&shim_fd->handle_lock);
    struct hash_entry *entry =
       _mesa_hash_table_search(shim_fd->handles, (void *)(uintptr_t)c->handle);
    if (!entry) {
-      mtx_unlock(&handle_lock);
+      mtx_unlock(&shim_fd->handle_lock);
       return -EINVAL;
    }
 
    struct shim_bo *bo = entry->data;
    _mesa_hash_table_remove(shim_fd->handles, entry);
    drm_shim_bo_put(bo);
-   mtx_unlock(&handle_lock);
+   mtx_unlock(&shim_fd->handle_lock);
    return 0;
 }
 
@@ -275,11 +275,11 @@ drm_shim_bo_lookup(struct shim_fd *shim_fd, int handle)
    if (!handle)
       return NULL;
 
-   mtx_lock(&handle_lock);
+   mtx_lock(&shim_fd->handle_lock);
    struct hash_entry *entry =
       _mesa_hash_table_search(shim_fd->handles, (void *)(uintptr_t)handle);
    struct shim_bo *bo = entry ? entry->data : NULL;
-   mtx_unlock(&handle_lock);
+   mtx_unlock(&shim_fd->handle_lock);
 
    if (bo)
       p_atomic_inc(&bo->refcount);
@@ -311,17 +311,17 @@ drm_shim_bo_get_handle(struct shim_fd *shim_fd, struct shim_bo *bo)
    /* We should probably have some real datastructure for finding the free
     * number.
     */
-   mtx_lock(&handle_lock);
+   mtx_lock(&shim_fd->handle_lock);
    for (int new_handle = 1; ; new_handle++) {
       void *key = (void *)(uintptr_t)new_handle;
       if (!_mesa_hash_table_search(shim_fd->handles, key)) {
          drm_shim_bo_get(bo);
          _mesa_hash_table_insert(shim_fd->handles, key, bo);
-         mtx_unlock(&handle_lock);
+         mtx_unlock(&shim_fd->handle_lock);
          return new_handle;
       }
    }
-   mtx_unlock(&handle_lock);
+   mtx_unlock(&shim_fd->handle_lock);
 
    return 0;
 }
diff --git a/src/drm-shim/drm_shim.h b/src/drm-shim/drm_shim.h
index 4a151d49bbc..4d359dd7f1a 100644
--- a/src/drm-shim/drm_shim.h
+++ b/src/drm-shim/drm_shim.h
@@ -21,6 +21,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <c11/threads.h>
+
 #include "util/macros.h"
 #include "util/hash_table.h"
 
@@ -53,6 +55,7 @@ extern struct shim_device shim_device;
 
 struct shim_fd {
    int fd;
+   mtx_t handle_lock;
    /* mapping from int gem handle to struct shim_bo *. */
    struct hash_table *handles;
 };



More information about the mesa-commit mailing list