Add helper function to set GstObject pointers with proper ref/unref sequence.
authorWim Taymans <wim.taymans@gmail.com>
Fri, 17 Jan 2003 17:44:07 +0000 (17:44 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Fri, 17 Jan 2003 17:44:07 +0000 (17:44 +0000)
Original commit message from CVS:
Add helper function to set GstObject pointers with proper ref/unref
sequence.

gst/gstobject.c
gst/gstobject.h

index 77a01698ee82a52d7eb1a34fc1525fff0abd190a..6de04bf9659da64b26759b2b4c29f9de4f96276c 100644 (file)
@@ -228,6 +228,27 @@ gst_object_sink (GstObject *object)
   }
 }
 
+/**
+ * gst_object_swap:
+ * @oldobj: pointer to place of old GstObject
+ * @newobj: new GstObject
+ *
+ * Unrefs the object pointer to by oldobj, refs the newobj and
+ * puts the newobj in *oldobj.
+ */
+void
+gst_object_swap (GstObject **oldobj, GstObject *newobj)
+{
+  if (*oldobj != newobj) {
+    if (newobj)
+      gst_object_ref (newobj);
+    if (*oldobj)
+      gst_object_unref (*oldobj);
+
+    *oldobj = newobj;
+  }
+}
+
 /**
  * gst_object_destroy:
  * @object: GstObject to destroy
index faf273b64b31cfef1f100c95b7f781839ebdbe9e..2291003d802b4d7e4381621bd815c15eecac8272 100644 (file)
@@ -146,6 +146,8 @@ void                gst_object_restore_thyself      (GstObject *object, xmlNodePtr self);
 GstObject *    gst_object_ref                  (GstObject *object);
 void           gst_object_unref                (GstObject *object);
 void           gst_object_sink                 (GstObject *object);
+
+void           gst_object_swap                 (GstObject **oldobj, GstObject *newobj);
 /* destroying an object */
 void           gst_object_destroy              (GstObject *object);