965: fix various refcount issues
authorKeith Whitwell <keith@tungstengraphics.com>
Thu, 3 Jan 2008 19:46:59 +0000 (19:46 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Fri, 4 Jan 2008 01:20:41 +0000 (01:20 +0000)
src/mesa/pipe/xlib/xm_winsys_aub.c

index b207638..2be8f87 100644 (file)
@@ -99,6 +99,8 @@ static void *aub_buffer_map(struct pipe_winsys *winsys,
 {
    struct aub_buffer *sbo = aub_bo(buf);
 
+   assert(sbo->data);
+
    if (flags & PIPE_BUFFER_FLAG_WRITE)
       sbo->dump_on_unmap = 1;
 
@@ -116,6 +118,9 @@ static void aub_buffer_unmap(struct pipe_winsys *winsys,
 
    if (sbo->map_count == 0 &&
        sbo->dump_on_unmap) {
+
+      sbo->dump_on_unmap = 0;
+
       brw_aub_gtt_data( iws->aubfile, 
                        sbo->offset,
                        sbo->data,
@@ -132,6 +137,7 @@ aub_buffer_reference(struct pipe_winsys *winsys,
                       struct pipe_buffer_handle *buf)
 {
    if (*ptr) {
+      assert(aub_bo(*ptr)->refcount != 0);
       if (--(aub_bo(*ptr)->refcount) == 0)
         free(*ptr);
       *ptr = NULL;
@@ -273,7 +279,9 @@ aub_buffer_create(struct pipe_winsys *winsys,
                      unsigned flags,
                      unsigned hint)
 {
-   return pipe_bo(CALLOC_STRUCT(aub_buffer));
+   struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer);
+   sbo->refcount = 1;
+   return pipe_bo(sbo);
 }
 
 
@@ -282,6 +290,8 @@ aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes)
 {
    struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer);
 
+   sbo->refcount = 1;
+
    /* Lets hope this is meant for upload, not as a result!  
     */
    aub_buffer_data( winsys,