this is a port of the r300 winsys code to do the same thing.
#include <sys/ioctl.h>
#include "util/u_inlines.h"
#include "util/u_debug.h"
+#include "util/u_hash_table.h"
#include <pipebuffer/pb_bufmgr.h>
#include "r600.h"
#include "r600_priv.h"
return 0;
}
+#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
+
+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 struct radeon *radeon_new(int fd, unsigned device)
{
struct radeon *radeon;
radeon_decref(radeon);
return NULL;
}
+
+ radeon->bo_handles = util_hash_table_create(handle_hash, handle_compare);
+ pipe_mutex_init(radeon->bo_handles_mutex);
return radeon;
}
return NULL;
}
+ util_hash_table_destroy(radeon->bo_handles);
+ pipe_mutex_destroy(radeon->bo_handles_mutex);
if (radeon->fence_bo) {
r600_bo_reference(radeon, &radeon->fence_bo, NULL);
}
#include <assert.h>
#include <util/u_double_list.h>
#include <util/u_inlines.h>
+#include "util/u_hash_table.h"
#include <os/os_thread.h>
#include "r600.h"
unsigned clock_crystal_freq;
unsigned num_backends;
unsigned minor_version;
+
+ /* List of buffer handles and its mutex. */
+ struct util_hash_table *bo_handles;
+ pipe_mutex bo_handles_mutex;
};
struct r600_reg {
struct r600_reloc *reloc;
unsigned reloc_id;
unsigned last_flush;
+ unsigned name;
};
struct r600_bo {
struct radeon_bo *bo;
int r;
+ if (handle) {
+ pipe_mutex_lock(radeon->bo_handles_mutex);
+ bo = util_hash_table_get(radeon->bo_handles,
+ (void *)(uintptr_t)handle);
+ if (bo) {
+ struct radeon_bo *b = NULL;
+ radeon_bo_reference(radeon, &b, bo);
+ goto done;
+ }
+ }
bo = calloc(1, sizeof(*bo));
if (bo == NULL) {
return NULL;
free(bo);
return NULL;
}
+ bo->name = handle;
bo->handle = open_arg.handle;
bo->size = open_arg.size;
bo->shared = TRUE;
radeon_bo_reference(radeon, &bo, NULL);
return bo;
}
+
+ if (handle)
+ util_hash_table_set(radeon->bo_handles, (void *)(uintptr_t)handle, bo);
+done:
+ if (handle)
+ pipe_mutex_unlock(radeon->bo_handles_mutex);
+
return bo;
}
{
struct drm_gem_close args;
+ if (bo->name) {
+ pipe_mutex_lock(radeon->bo_handles_mutex);
+ util_hash_table_remove(radeon->bo_handles,
+ (void *)(uintptr_t)bo->name);
+ pipe_mutex_unlock(radeon->bo_handles_mutex);
+ }
LIST_DEL(&bo->fencedlist);
radeon_bo_fixed_unmap(radeon, bo);
memset(&args, 0, sizeof(args));