Instead of the hash use the handle table. Signed-off-by: Christian König <christian.koenig at amd.com> --- amdgpu/amdgpu_bo.c | 26 +++++++++++++------------- amdgpu/amdgpu_device.c | 15 +-------------- amdgpu/amdgpu_internal.h | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 66edb8d4..02592377 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -37,7 +37,6 @@ #include "xf86drm.h" #include "amdgpu_drm.h" #include "amdgpu_internal.h" -#include "util_hash_table.h" #include "util_math.h" static void amdgpu_close_kms_handle(amdgpu_device_handle dev, @@ -219,12 +218,10 @@ static int amdgpu_bo_export_flink(amdgpu_bo_handle bo) } pthread_mutex_lock(&bo->dev->bo_table_mutex); - util_hash_table_set(bo->dev->bo_flink_names, - (void*)(uintptr_t)bo->flink_name, - bo); + r = handle_table_insert(&bo->dev->bo_flink_names, bo->flink_name, bo); pthread_mutex_unlock(&bo->dev->bo_table_mutex); - return 0; + return r; } int amdgpu_bo_export(amdgpu_bo_handle bo, @@ -301,8 +298,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev, /* If we have already created a buffer with this handle, find it. */ switch (type) { case amdgpu_bo_handle_type_gem_flink_name: - bo = util_hash_table_get(dev->bo_flink_names, - (void*)(uintptr_t)shared_handle); + bo = handle_table_lookup(&dev->bo_flink_names, shared_handle); break; case amdgpu_bo_handle_type_dma_buf_fd: @@ -370,8 +366,13 @@ int amdgpu_bo_import(amdgpu_device_handle dev, } bo->flink_name = shared_handle; bo->alloc_size = open_arg.size; - util_hash_table_set(dev->bo_flink_names, - (void*)(uintptr_t)bo->flink_name, bo); + r = handle_table_insert(&dev->bo_flink_names, shared_handle, + bo); + if (r) { + pthread_mutex_unlock(&dev->bo_table_mutex); + amdgpu_bo_free(bo); + return r; + } break; case amdgpu_bo_handle_type_dma_buf_fd: @@ -410,10 +411,9 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle) /* Remove the buffer from the hash tables. */ handle_table_remove(&dev->bo_handles, bo->handle); - if (bo->flink_name) { - util_hash_table_remove(dev->bo_flink_names, - (void*)(uintptr_t)bo->flink_name); - } + if (bo->flink_name) + handle_table_remove(&dev->bo_flink_names, + bo->flink_name); /* Release CPU access. */ if (bo->cpu_map_count > 0) { diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c index 824c1dae..73eeeed6 100644 --- a/amdgpu/amdgpu_device.c +++ b/amdgpu/amdgpu_device.c @@ -39,7 +39,6 @@ #include "xf86drm.h" #include "amdgpu_drm.h" #include "amdgpu_internal.h" -#include "util_hash_table.h" #include "util_math.h" #define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x))) @@ -47,16 +46,6 @@ static pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER; static amdgpu_device_handle fd_list; -static unsigned handle_hash(void *key) -{ - return PTR_TO_UINT(key); -} - -static int handle_compare(void *key1, void *key2) -{ - return PTR_TO_UINT(key1) != PTR_TO_UINT(key2); -} - static int fd_compare(int fd1, int fd2) { char *name1 = drmGetPrimaryDeviceNameFromFd(fd1); @@ -123,7 +112,7 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev) amdgpu_vamgr_deinit(&dev->vamgr_high_32); amdgpu_vamgr_deinit(&dev->vamgr_high); handle_table_fini(&dev->bo_handles); - util_hash_table_destroy(dev->bo_flink_names); + handle_table_fini(&dev->bo_flink_names); pthread_mutex_destroy(&dev->bo_table_mutex); free(dev->marketing_name); free(dev); @@ -228,8 +217,6 @@ int amdgpu_device_initialize(int fd, dev->minor_version = version->version_minor; drmFreeVersion(version); - dev->bo_flink_names = util_hash_table_create(handle_hash, - handle_compare); pthread_mutex_init(&dev->bo_table_mutex, NULL); /* Check if acceleration is working. */ diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h index 36ebc738..a340abbd 100644 --- a/amdgpu/amdgpu_internal.h +++ b/amdgpu/amdgpu_internal.h @@ -76,7 +76,7 @@ struct amdgpu_device { /** List of buffer handles. Protected by bo_table_mutex. */ struct handle_table bo_handles; /** List of buffer GEM flink names. Protected by bo_table_mutex. */ - struct util_hash_table *bo_flink_names; + struct handle_table bo_flink_names; /** This protects all hash tables. */ pthread_mutex_t bo_table_mutex; struct drm_amdgpu_info_device dev_info; -- 2.14.1