diff options
Diffstat (limited to 'src/gallium/auxiliary/pipebuffer')
9 files changed, 37 insertions, 47 deletions
diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h b/src/gallium/auxiliary/pipebuffer/pb_buffer.h index e6b0b30ff44..be1654c654a 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer.h +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h @@ -159,7 +159,7 @@ pb_map(struct pb_buffer *buf, assert(buf); if(!buf) return NULL; - assert(buf->base.refcount > 0); + assert(buf->base.reference.count > 0); return buf->vtbl->map(buf, flags); } @@ -170,7 +170,7 @@ pb_unmap(struct pb_buffer *buf) assert(buf); if(!buf) return; - assert(buf->base.refcount > 0); + assert(buf->base.reference.count > 0); buf->vtbl->unmap(buf); } @@ -186,7 +186,7 @@ pb_get_base_buffer( struct pb_buffer *buf, offset = 0; return; } - assert(buf->base.refcount > 0); + assert(buf->base.reference.count > 0); assert(buf->vtbl->get_base_buffer); buf->vtbl->get_base_buffer(buf, base_buf, offset); assert(*base_buf); @@ -222,29 +222,18 @@ pb_destroy(struct pb_buffer *buf) assert(buf); if(!buf) return; - assert(buf->base.refcount == 0); + assert(buf->base.reference.count == 0); buf->vtbl->destroy(buf); } - -/* XXX: thread safety issues! - */ static INLINE void pb_reference(struct pb_buffer **dst, struct pb_buffer *src) { - if (src) { - assert(src->base.refcount); - src->base.refcount++; - } - - if (*dst) { - assert((*dst)->base.refcount); - if(--(*dst)->base.refcount == 0) - pb_destroy( *dst ); - } + struct pb_buffer *old = *dst; - *dst = src; + if (pipe_reference((struct pipe_reference**)dst, &src->base.reference)) + pb_destroy( old ); } diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c index 17ff61b675c..e4adf8aad7c 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c @@ -115,7 +115,7 @@ _fenced_buffer_add(struct fenced_buffer *fenced_buf) { struct fenced_buffer_list *fenced_list = fenced_buf->list; - assert(fenced_buf->base.base.refcount); + assert(fenced_buf->base.base.reference.count); assert(fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE); assert(fenced_buf->fence); @@ -137,7 +137,7 @@ _fenced_buffer_destroy(struct fenced_buffer *fenced_buf) { struct fenced_buffer_list *fenced_list = fenced_buf->list; - assert(!fenced_buf->base.base.refcount); + assert(!fenced_buf->base.base.reference.count); assert(!fenced_buf->fence); #ifdef DEBUG assert(fenced_buf->head.prev); @@ -177,7 +177,7 @@ _fenced_buffer_remove(struct fenced_buffer_list *fenced_list, ++fenced_list->numUnfenced; #endif - if(!fenced_buf->base.base.refcount) + if(!fenced_buf->base.base.reference.count) _fenced_buffer_destroy(fenced_buf); } @@ -253,7 +253,7 @@ fenced_buffer_destroy(struct pb_buffer *buf) struct fenced_buffer_list *fenced_list = fenced_buf->list; pipe_mutex_lock(fenced_list->mutex); - assert(fenced_buf->base.base.refcount == 0); + assert(fenced_buf->base.base.reference.count == 0); if (fenced_buf->fence) { struct pb_fence_ops *ops = fenced_list->ops; if(ops->fence_signalled(ops, fenced_buf->fence, 0) == 0) { @@ -461,7 +461,7 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list, return NULL; } - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = buffer->base.alignment; buf->base.base.usage = buffer->base.usage; buf->base.base.size = buffer->base.size; @@ -527,7 +527,7 @@ fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) pipe_mutex_lock(fenced_list->mutex); debug_printf("%10s %7s %10s %s\n", - "buffer", "refcount", "fence", "signalled"); + "buffer", "reference.count", "fence", "signalled"); curr = fenced_list->unfenced.next; next = curr->next; @@ -536,7 +536,7 @@ fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) assert(!fenced_buf->fence); debug_printf("%10p %7u\n", fenced_buf, - fenced_buf->base.base.refcount); + fenced_buf->base.base.reference.count); curr = next; next = curr->next; } @@ -549,7 +549,7 @@ fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) signaled = ops->fence_signalled(ops, fenced_buf->fence, 0); debug_printf("%10p %7u %10p %s\n", fenced_buf, - fenced_buf->base.base.refcount, + fenced_buf->base.base.reference.count, fenced_buf->fence, signaled == 0 ? "y" : "n"); curr = next; diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c index 282802b1717..689fd74771f 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c @@ -132,7 +132,7 @@ pb_malloc_buffer_create(size_t size, if(!buf) return NULL; - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c index 29117efe9bd..06ed0002ca8 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c @@ -112,7 +112,7 @@ _pb_cache_buffer_destroy(struct pb_cache_buffer *buf) LIST_DEL(&buf->head); assert(mgr->numDelayed); --mgr->numDelayed; - assert(!buf->base.base.refcount); + assert(!buf->base.base.reference.count); pb_reference(&buf->buffer, NULL); FREE(buf); } @@ -153,7 +153,7 @@ pb_cache_buffer_destroy(struct pb_buffer *_buf) struct pb_cache_manager *mgr = buf->mgr; pipe_mutex_lock(mgr->mutex); - assert(buf->base.base.refcount == 0); + assert(buf->base.base.reference.count == 0); _pb_cache_buffer_list_check_free(mgr); @@ -293,7 +293,8 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr, if(buf) { LIST_DEL(&buf->head); pipe_mutex_unlock(mgr->mutex); - ++buf->base.base.refcount; + /* Increase refcount */ + pb_reference((struct pb_buffer**)&buf, &buf->base); return &buf->base; } @@ -309,12 +310,12 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr, return NULL; } - assert(buf->buffer->base.refcount >= 1); + assert(buf->buffer->base.reference.count >= 1); assert(pb_check_alignment(desc->alignment, buf->buffer->base.alignment)); assert(pb_check_usage(desc->usage, buf->buffer->base.usage)); assert(buf->buffer->base.size >= size); - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = buf->buffer->base.alignment; buf->base.base.usage = buf->buffer->base.usage; buf->base.base.size = buf->buffer->base.size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c index 21079b8bfd7..37ed64b84f6 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c @@ -206,9 +206,9 @@ pb_debug_buffer_check(struct pb_debug_buffer *buf) static void pb_debug_buffer_destroy(struct pb_buffer *_buf) { - struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); - assert(!buf->base.base.refcount); + assert(!buf->base.base.reference.count); pb_debug_buffer_check(buf); @@ -315,12 +315,12 @@ pb_debug_manager_create_buffer(struct pb_manager *_mgr, return NULL; } - assert(buf->buffer->base.refcount >= 1); + assert(buf->buffer->base.reference.count >= 1); assert(pb_check_alignment(real_desc.alignment, buf->buffer->base.alignment)); assert(pb_check_usage(real_desc.usage, buf->buffer->base.usage)); assert(buf->buffer->base.size >= real_size); - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c index 85ff3a09de4..9b0f77bedb4 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c @@ -97,11 +97,11 @@ mm_buffer_destroy(struct pb_buffer *buf) struct mm_buffer *mm_buf = mm_buffer(buf); struct mm_pb_manager *mm = mm_buf->mgr; - assert(buf->base.refcount == 0); + assert(mm_buf->base.base.reference.count == 0); pipe_mutex_lock(mm->mutex); u_mmFreeMem(mm_buf->block); - FREE(buf); + FREE(mm_buf); pipe_mutex_unlock(mm->mutex); } @@ -189,7 +189,7 @@ mm_bufmgr_create_buffer(struct pb_manager *mgr, return NULL; } - mm_buf->base.base.refcount = 1; + pipe_reference_init(&mm_buf->base.base.reference, 1); mm_buf->base.base.alignment = desc->alignment; mm_buf->base.base.usage = desc->usage; mm_buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c index 3d9c7bba0ba..4f7e6b1c4df 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c @@ -242,7 +242,7 @@ pb_ondemand_manager_create_buffer(struct pb_manager *_mgr, if(!buf) return NULL; - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c index 12447acfd93..ca6c14a627e 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c @@ -108,7 +108,7 @@ pool_buffer_destroy(struct pb_buffer *buf) struct pool_buffer *pool_buf = pool_buffer(buf); struct pool_pb_manager *pool = pool_buf->mgr; - assert(pool_buf->base.base.refcount == 0); + assert(pool_buf->base.base.reference.count == 0); pipe_mutex_lock(pool->mutex); LIST_ADD(&pool_buf->head, &pool->free); @@ -216,8 +216,8 @@ pool_bufmgr_create_buffer(struct pb_manager *mgr, pipe_mutex_unlock(pool->mutex); pool_buf = LIST_ENTRY(struct pool_buffer, item, head); - assert(pool_buf->base.base.refcount == 0); - pool_buf->base.base.refcount = 1; + assert(pool_buf->base.base.reference.count == 0); + pipe_reference_init(&pool_buf->base.base.reference, 1); pool_buf->base.base.alignment = desc->alignment; pool_buf->base.base.usage = desc->usage; @@ -295,7 +295,7 @@ pool_bufmgr_create(struct pb_manager *provider, pool_buf = pool->bufs; for (i = 0; i < numBufs; ++i) { - pool_buf->base.base.refcount = 0; + pipe_reference_init(&pool_buf->base.base.reference, 0); pool_buf->base.base.alignment = 0; pool_buf->base.base.usage = 0; pool_buf->base.base.size = bufSize; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c index a3259351b92..2cdb5a5e29d 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c @@ -202,7 +202,7 @@ pb_slab_buffer_destroy(struct pb_buffer *_buf) pipe_mutex_lock(mgr->mutex); - assert(buf->base.base.refcount == 0); + assert(buf->base.base.reference.count == 0); buf->mapCount = 0; @@ -340,7 +340,7 @@ pb_slab_create(struct pb_slab_manager *mgr) buf = slab->buffers; for (i=0; i < numBuffers; ++i) { - buf->base.base.refcount = 0; + pipe_reference_init(&buf->base.base.reference, 0); buf->base.base.size = mgr->bufSize; buf->base.base.alignment = 0; buf->base.base.usage = 0; @@ -419,7 +419,7 @@ pb_slab_manager_create_buffer(struct pb_manager *_mgr, pipe_mutex_unlock(mgr->mutex); buf = LIST_ENTRY(struct pb_slab_buffer, list, head); - ++buf->base.base.refcount; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; |