Instead of the hash use the handle table. Signed-off-by: Christian König <christian.koenig at amd.com> --- amdgpu/amdgpu_bo.c | 19 ++++++++++--------- amdgpu/amdgpu_device.c | 3 +-- amdgpu/amdgpu_internal.h | 3 ++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index d29be244..66edb8d4 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -90,8 +90,12 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev, pthread_mutex_init(&bo->cpu_access_mutex, NULL); - *buf_handle = bo; - return 0; + if (r) + amdgpu_bo_free(bo); + else + *buf_handle = bo; + + return r; } int amdgpu_bo_set_metadata(amdgpu_bo_handle bo, @@ -171,8 +175,7 @@ int amdgpu_bo_query_info(amdgpu_bo_handle bo, static void amdgpu_add_handle_to_table(amdgpu_bo_handle bo) { pthread_mutex_lock(&bo->dev->bo_table_mutex); - util_hash_table_set(bo->dev->bo_handles, - (void*)(uintptr_t)bo->handle, bo); + handle_table_insert(&bo->dev->bo_handles, bo->handle, bo); pthread_mutex_unlock(&bo->dev->bo_table_mutex); } @@ -303,8 +306,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev, break; case amdgpu_bo_handle_type_dma_buf_fd: - bo = util_hash_table_get(dev->bo_handles, - (void*)(uintptr_t)shared_handle); + bo = handle_table_lookup(&dev->bo_handles, shared_handle); break; case amdgpu_bo_handle_type_kms: @@ -387,7 +389,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev, bo->dev = dev; pthread_mutex_init(&bo->cpu_access_mutex, NULL); - util_hash_table_set(dev->bo_handles, (void*)(uintptr_t)bo->handle, bo); + handle_table_insert(&dev->bo_handles, bo->handle, bo); pthread_mutex_unlock(&dev->bo_table_mutex); output->buf_handle = bo; @@ -406,8 +408,7 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle) if (update_references(&bo->refcount, NULL)) { /* Remove the buffer from the hash tables. */ - util_hash_table_remove(dev->bo_handles, - (void*)(uintptr_t)bo->handle); + handle_table_remove(&dev->bo_handles, bo->handle); if (bo->flink_name) { util_hash_table_remove(dev->bo_flink_names, diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c index 38fd186d..824c1dae 100644 --- a/amdgpu/amdgpu_device.c +++ b/amdgpu/amdgpu_device.c @@ -122,8 +122,8 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev) amdgpu_vamgr_deinit(&dev->vamgr); 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); - util_hash_table_destroy(dev->bo_handles); pthread_mutex_destroy(&dev->bo_table_mutex); free(dev->marketing_name); free(dev); @@ -230,7 +230,6 @@ int amdgpu_device_initialize(int fd, dev->bo_flink_names = util_hash_table_create(handle_hash, handle_compare); - dev->bo_handles = 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 83012cab..36ebc738 100644 --- a/amdgpu/amdgpu_internal.h +++ b/amdgpu/amdgpu_internal.h @@ -32,6 +32,7 @@ #include "xf86atomic.h" #include "amdgpu.h" #include "util_double_list.h" +#include "handle_table.h" #define AMDGPU_CS_MAX_RINGS 8 /* do not use below macro if b is not power of 2 aligned value */ @@ -73,7 +74,7 @@ struct amdgpu_device { char *marketing_name; /** List of buffer handles. Protected by bo_table_mutex. */ - struct util_hash_table *bo_handles; + struct handle_table bo_handles; /** List of buffer GEM flink names. Protected by bo_table_mutex. */ struct util_hash_table *bo_flink_names; /** This protects all hash tables. */ -- 2.14.1