Mesa (mesa_7_5_branch): gallium: Avoid atomic ops / locking when src is dst .

Jose Fonseca jrfonseca at kemper.freedesktop.org
Tue Jun 16 13:33:12 UTC 2009


Module: Mesa
Branch: mesa_7_5_branch
Commit: 3463b1479d1c70e3b23189c72132e9ad5f710ff9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3463b1479d1c70e3b23189c72132e9ad5f710ff9

Author: José Fonseca <jfonseca at vmware.com>
Date:   Tue Jun 16 13:05:25 2009 +0100

gallium: Avoid atomic ops / locking when src is dst.

---

 src/gallium/include/pipe/p_refcnt.h |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h
index 1f89453..1f9088b 100644
--- a/src/gallium/include/pipe/p_refcnt.h
+++ b/src/gallium/include/pipe/p_refcnt.h
@@ -62,29 +62,29 @@ pipe_is_referenced(struct pipe_reference *reference)
  * Set 'ptr' to point to 'reference' and update reference counting.
  * The old thing pointed to, if any, will be unreferenced first.
  * 'reference' may be NULL.
- *
- * XXX: thread safety issues!
  */
 static INLINE bool
 pipe_reference(struct pipe_reference **ptr, struct pipe_reference *reference)
 {
    bool destroy = FALSE;
 
-   /* bump the reference.count first */
-   if (reference) {
-      assert(pipe_is_referenced(reference));
-      p_atomic_inc(&reference->count);
-   }
-
-   if (*ptr) {
-      assert(pipe_is_referenced(*ptr));
-      if (p_atomic_dec_zero(&(*ptr)->count)) {
-         destroy = TRUE;
+   if(*ptr != reference) {
+      /* bump the reference.count first */
+      if (reference) {
+         assert(pipe_is_referenced(reference));
+         p_atomic_inc(&reference->count);
       }
+   
+      if (*ptr) {
+         assert(pipe_is_referenced(*ptr));
+         if (p_atomic_dec_zero(&(*ptr)->count)) {
+            destroy = TRUE;
+         }
+      }
+   
+      *ptr = reference;
    }
 
-   *ptr = reference;
-
    return destroy;
 }
 




More information about the mesa-commit mailing list