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,
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);
}
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:
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;
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,
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);
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. */
#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 */
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. */