ilo: fix fence reference counting
authorChia-I Wu <olvaffe@gmail.com>
Tue, 8 Jul 2014 06:03:17 +0000 (14:03 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 8 Jul 2014 07:00:36 +0000 (15:00 +0800)
The old code was complicated, and was wrong when *ptr is NULL.

src/gallium/drivers/ilo/ilo_screen.c

index a7eaa1b3157e833b7ee9a7e0e966d1d1eafba938..4e4739c450405c5c91a1fb860984b5438cb70503 100644 (file)
@@ -529,26 +529,23 @@ ilo_fence_reference(struct pipe_screen *screen,
                     struct pipe_fence_handle **p,
                     struct pipe_fence_handle *f)
 {
-   struct ilo_fence **ptr = (struct ilo_fence **) p;
    struct ilo_fence *fence = ilo_fence(f);
+   struct ilo_fence *old;
 
-   if (!ptr) {
-      /* still need to reference fence */
-      if (fence)
-         pipe_reference(NULL, &fence->reference);
-      return;
+   if (likely(p)) {
+      old = ilo_fence(*p);
+      *p = f;
+   }
+   else {
+      old = NULL;
    }
 
-   /* reference fence and dereference the one pointed to by ptr */
-   if (*ptr && pipe_reference(&(*ptr)->reference, &fence->reference)) {
-      struct ilo_fence *old = *ptr;
-
+   STATIC_ASSERT(&((struct ilo_fence *) NULL)->reference == NULL);
+   if (pipe_reference(&old->reference, &fence->reference)) {
       if (old->bo)
          intel_bo_unreference(old->bo);
       FREE(old);
    }
-
-   *ptr = fence;
 }
 
 static boolean