gst/gstminiobject.c: When replacing a miniobject, do a quick equality check first...
authorWim Taymans <wim.taymans@gmail.com>
Fri, 1 Feb 2008 10:23:56 +0000 (10:23 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Fri, 1 Feb 2008 10:23:56 +0000 (10:23 +0000)
Original commit message from CVS:
* gst/gstminiobject.c: (gst_mini_object_replace):
When replacing a miniobject, do a quick equality check first so that we
can avoid a ref/unref pair.

ChangeLog
gst/gstminiobject.c

index cdb4bbf..234bb22 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-02-01  Wim Taymans  <wim.taymans@collabora.co.uk>
 
+       * gst/gstminiobject.c: (gst_mini_object_replace):
+       When replacing a miniobject, do a quick equality check first so that we
+       can avoid a ref/unref pair.
+
+2008-02-01  Wim Taymans  <wim.taymans@collabora.co.uk>
+
        * docs/design/part-synchronisation.txt:
        Update some docs.
 
index 636ff98..7d19248 100644 (file)
@@ -364,13 +364,18 @@ gst_mini_object_replace (GstMiniObject ** olddata, GstMiniObject * newdata)
       newdata, newdata ? newdata->refcount : 0);
 #endif
 
+  olddata_val = g_atomic_pointer_get ((gpointer *) olddata);
+
+  if (olddata_val == newdata)
+    return;
+
   if (newdata)
     gst_mini_object_ref (newdata);
 
-  do {
+  while (!g_atomic_pointer_compare_and_exchange ((gpointer *) olddata,
+          olddata_val, newdata)) {
     olddata_val = g_atomic_pointer_get ((gpointer *) olddata);
-  } while (!g_atomic_pointer_compare_and_exchange ((gpointer *) olddata,
-          olddata_val, newdata));
+  }
 
   if (olddata_val)
     gst_mini_object_unref (olddata_val);