Do refcounting trhoughout all buffer objects, since it is now a base requirement.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Sun, 27 Jan 2008 10:22:25 +0000 (19:22 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Sun, 27 Jan 2008 10:22:25 +0000 (19:22 +0900)
src/mesa/pipe/pipebuffer/pb_buffer_fenced.c
src/mesa/pipe/pipebuffer/pb_buffer_malloc.c
src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c
src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c

index b2edc321ef4a3d74ba8d09a97823f0c41df39a18..349647fe6e4bd2b7ef5de15d8d228042befa5eba 100644 (file)
@@ -80,7 +80,6 @@ struct fenced_buffer
    
    struct pb_buffer *buffer;
 
-   unsigned refcount;
    struct pipe_fence_handle *fence;
 
    struct list_head head;
@@ -145,7 +144,7 @@ _fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list,
 
       /* Do the delayed destroy:
        */
-      pb_destroy(fenced_buf->buffer);
+      pb_reference(&fenced_buf->buffer, NULL);
       free(fenced_buf);
    }
 }
@@ -162,7 +161,7 @@ fenced_buffer_destroy(struct pb_buffer *buf)
       fenced_list->numDelayed++;
    }
    else {
-      pb_destroy(fenced_buf->buffer);
+      pb_reference(&fenced_buf->buffer, NULL);
       free(fenced_buf);
    }
    
@@ -220,9 +219,13 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list,
    if(!buf)
       return NULL;
    
+   buf->base.base.refcount = 1;
+   buf->base.base.alignment = buffer->base.alignment;
+   buf->base.base.usage = buffer->base.usage;
+   buf->base.base.size = buffer->base.size;
+   
    buf->base.vtbl = &fenced_buffer_vtbl;
    buf->buffer = buffer;
-   buf->refcount = 1;
    buf->list = fenced_list;
    
    return &buf->base;
index f0ff1d347e80dab00ddc06533d8cb0e319b6fc23..fc83a00f3673e4e527b2d49f85ec6ab9a3104f81 100644 (file)
@@ -114,10 +114,11 @@ pb_malloc_buffer_create(size_t size,
    if(!buf)
       return NULL;
    
-   buf->base.vtbl = &malloc_buffer_vtbl;
+   buf->base.base.refcount = 1;
    buf->base.base.alignment = desc->alignment;
    buf->base.base.usage = desc->usage;
    buf->base.base.size = size;
+   buf->base.vtbl = &malloc_buffer_vtbl;
 
    buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment);
    if(!buf->data) {
index 6a81cbdae04da1f9c0446b9fc505a667861fa5e1..3b341c64c280c07a30fe87d71e16620735f6707a 100644 (file)
@@ -88,6 +88,7 @@ fenced_bufmgr_create_buffer(struct pb_manager *mgr,
    
    fenced_buf = fenced_buffer_create(fenced_mgr->fenced_list, buf);
    if(!fenced_buf) {
+      assert(buf->base.refcount == 1);
       pb_destroy(buf);
    }
    
index 2a62702c3664c63476944894bfae893f9726ea63..2694f57bca0e3430372d3348b56355479e0ecb81 100644 (file)
@@ -466,6 +466,11 @@ mm_bufmgr_create_buffer(struct pb_manager *mgr,
       return NULL;
    }
 
+   mm_buf->base.base.refcount = 1;
+   mm_buf->base.base.alignment = desc->alignment;
+   mm_buf->base.base.usage = desc->usage;
+   mm_buf->base.base.size = size;
+   
    mm_buf->base.vtbl = &mm_buffer_vtbl;
    
    mm_buf->mgr = mm;
@@ -505,7 +510,7 @@ mm_bufmgr_destroy(struct pb_manager *mgr)
    mmDestroy(mm->heap);
    
    pb_unmap(mm->buffer);
-   pb_destroy(mm->buffer);
+   pb_reference(&mm->buffer, NULL);
    
    _glthread_UNLOCK_MUTEX(mm->mutex);
    
@@ -579,7 +584,7 @@ mm_bufmgr_create(struct pb_manager *provider,
    
    mgr = mm_bufmgr_create_from_buffer(buffer, size, align2);
    if (!mgr) {
-      pb_destroy(buffer);
+      pb_reference(&buffer, NULL);
       return NULL;
    }
 
index 61c06ec82448ce9fec38cd55944cb975a4e49682..7c2995411227926be6ef9aa0bcbc2507e657f17a 100644 (file)
@@ -111,6 +111,8 @@ 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);
+
    _glthread_LOCK_MUTEX(pool->mutex);
    LIST_ADD(&pool_buf->head, &pool->free);
    pool->numFree++;
@@ -192,7 +194,13 @@ pool_bufmgr_create_buffer(struct pb_manager *mgr,
    --pool->numFree;
 
    _glthread_UNLOCK_MUTEX(pool->mutex);
+   
    pool_buf = LIST_ENTRY(struct pool_buffer, item, head);
+   assert(pool_buf->base.base.refcount == 0);
+   pool_buf->base.base.refcount = 1;
+   pool_buf->base.base.alignment = desc->alignment;
+   pool_buf->base.base.usage = desc->usage;
+   
    return SUPER(pool_buf);
 }
 
@@ -206,7 +214,7 @@ pool_bufmgr_destroy(struct pb_manager *mgr)
    FREE(pool->bufs);
    
    pb_unmap(pool->buffer);
-   pb_destroy(pool->buffer);
+   pb_reference(&pool->buffer, NULL);
    
    _glthread_UNLOCK_MUTEX(pool->mutex);
    
@@ -256,6 +264,10 @@ pool_bufmgr_create(struct pb_manager *provider,
 
    pool_buf = pool->bufs;
    for (i = 0; i < numBufs; ++i) {
+      pool_buf->base.base.refcount = 0;
+      pool_buf->base.base.alignment = 0;
+      pool_buf->base.base.usage = 0;
+      pool_buf->base.base.size = bufSize;
       pool_buf->base.vtbl = &pool_buffer_vtbl;
       pool_buf->mgr = pool;
       pool_buf->start = i * bufSize;
@@ -271,7 +283,7 @@ failure:
    if(pool->map)
       pb_unmap(pool->buffer);
    if(pool->buffer)
-      pb_destroy(pool->buffer);
+      pb_reference(&pool->buffer, NULL);
    if(pool)
       FREE(pool);
    return NULL;