From: Marek Olšák Date: Sun, 3 Apr 2011 15:32:47 +0000 (+0200) Subject: r300g: remove the redundant reference counter in radeon_bo X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c35572352e3e92683988ee8d151b47f4190d62f9;p=mesa.git r300g: remove the redundant reference counter in radeon_bo We already have pb_buffer::reference::count. --- diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c index 9eb833454df..eb7225b8738 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c @@ -87,29 +87,7 @@ static struct radeon_bo *get_radeon_bo(struct pb_buffer *_buf) return bo; } -void radeon_bo_unref(struct radeon_bo *bo) -{ - struct drm_gem_close args = {}; - - if (!p_atomic_dec_zero(&bo->ref_count)) - return; - - if (bo->name) { - pipe_mutex_lock(bo->mgr->bo_handles_mutex); - util_hash_table_remove(bo->mgr->bo_handles, - (void*)(uintptr_t)bo->name); - pipe_mutex_unlock(bo->mgr->bo_handles_mutex); - } - if (bo->ptr) - munmap(bo->ptr, bo->size); - - /* Close object. */ - args.handle = bo->handle; - drmIoctl(bo->rws->fd, DRM_IOCTL_GEM_CLOSE, &args); - pipe_mutex_destroy(bo->map_mutex); - FREE(bo); -} static void radeon_bo_wait(struct r300_winsys_bo *_buf) { @@ -142,8 +120,23 @@ static boolean radeon_bo_is_busy(struct r300_winsys_bo *_buf) static void radeon_bo_destroy(struct pb_buffer *_buf) { struct radeon_bo *bo = radeon_bo(_buf); + struct drm_gem_close args = {}; + + if (bo->name) { + pipe_mutex_lock(bo->mgr->bo_handles_mutex); + util_hash_table_remove(bo->mgr->bo_handles, + (void*)(uintptr_t)bo->name); + pipe_mutex_unlock(bo->mgr->bo_handles_mutex); + } - radeon_bo_unref(bo); + if (bo->ptr) + munmap(bo->ptr, bo->size); + + /* Close object. */ + args.handle = bo->handle; + drmIoctl(bo->rws->fd, DRM_IOCTL_GEM_CLOSE, &args); + pipe_mutex_destroy(bo->map_mutex); + FREE(bo); } static unsigned get_pb_usage_from_transfer_flags(enum pipe_transfer_usage usage) @@ -300,7 +293,6 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr, bo->size = size; pipe_mutex_init(bo->map_mutex); - radeon_bo_ref(bo); return &bo->base; } @@ -531,7 +523,6 @@ static struct r300_winsys_bo *radeon_winsys_bo_from_handle(struct r300_winsys_sc bo->handle = open_arg.handle; bo->size = open_arg.size; bo->name = whandle->handle; - radeon_bo_ref(bo); /* Initialize it. */ pipe_reference_init(&bo->base.base.reference, 1); diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.h b/src/gallium/winsys/radeon/drm/radeon_drm_bo.h index a26866b7e75..3f9a63f5f11 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.h +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.h @@ -54,8 +54,6 @@ struct radeon_bo { uint32_t handle; uint32_t name; - int ref_count; - /* how many command streams is this bo referenced in? */ int num_cs_references; @@ -70,12 +68,10 @@ struct radeon_bo { struct pb_manager *radeon_bomgr_create(struct radeon_drm_winsys *rws); void radeon_bomgr_init_functions(struct radeon_drm_winsys *ws); -void radeon_bo_unref(struct radeon_bo *buf); - - -static INLINE void radeon_bo_ref(struct radeon_bo *bo) +static INLINE +void radeon_bo_reference(struct radeon_bo **dst, struct radeon_bo *src) { - p_atomic_inc(&bo->ref_count); + pb_reference((struct pb_buffer**)dst, (struct pb_buffer*)src); } static INLINE struct pb_buffer * diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c index 951791a1727..4adf4ade770 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c @@ -111,8 +111,7 @@ static void radeon_cs_context_cleanup(struct radeon_cs_context *csc) for (i = 0; i < csc->crelocs; i++) { p_atomic_dec(&csc->relocs_bo[i]->num_cs_references); - radeon_bo_unref(csc->relocs_bo[i]); - csc->relocs_bo[i] = NULL; + radeon_bo_reference(&csc->relocs_bo[i], NULL); } csc->crelocs = 0; @@ -266,9 +265,8 @@ static void radeon_add_reloc(struct radeon_cs_context *csc, } /* Initialize the new relocation. */ - radeon_bo_ref(bo); p_atomic_inc(&bo->num_cs_references); - csc->relocs_bo[csc->crelocs] = bo; + radeon_bo_reference(&csc->relocs_bo[csc->crelocs], bo); reloc = &csc->relocs[csc->crelocs]; reloc->handle = bo->handle; reloc->read_domains = rd;