Example #1
0
/* allocate a new buffer object, call w/ table_lock held */
static struct omap_bo * bo_from_handle(struct omap_device *dev,
		uint32_t handle)
{
	struct omap_bo *bo = calloc(sizeof(*bo), 1);
	if (!bo) {
		struct drm_gem_close req = {
				.handle = handle,
		};
		drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
		return NULL;
	}
	bo->dev = omap_device_ref(dev);
	bo->handle = handle;
	atomic_set(&bo->refcnt, 1);
	/* add ourselves to the handle table: */
	drmHashInsert(dev->handle_table, handle, bo);
	return bo;
}
Example #2
0
drm_public struct omap_device * omap_device_new(int fd)
{
	struct omap_device *dev = NULL;

	pthread_mutex_lock(&table_lock);

	if (!dev_table)
		dev_table = drmHashCreate();

	if (drmHashLookup(dev_table, fd, (void **)&dev)) {
		/* not found, create new device */
		dev = omap_device_new_impl(fd);
		drmHashInsert(dev_table, fd, dev);
	} else {
		/* found, just incr refcnt */
		dev = omap_device_ref(dev);
	}

	pthread_mutex_unlock(&table_lock);

	return dev;
}