summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2005-09-20 11:09:50 +0000
committerAndy Wingo <wingo@pobox.com>2005-09-20 11:09:50 +0000
commitb12471008b879a4e5c3951b817d52a8ab4bfa699 (patch)
tree9d5ab53006558e57a2541d5569df1c7619633adc /gst
parent2ed824baac7e650ed2c922aedc62aedf4ea55ebc (diff)
gst/gstelementfactory.c (gst_element_factory_create): Avoid eating the caller's refcount.
Original commit message from CVS: 2005-09-20 Andy Wingo <wingo@pobox.com> * gst/gstelementfactory.c (gst_element_factory_create): Avoid eating the caller's refcount. * gst/gstobject.h (GST_OBJECT_REFCOUNT) (GST_OBJECT_REFCOUNT_VALUE): Conditionally fondle the right refcount. * gst/gstconfig.h.in (GST_HAVE_GLIB_2_8): * configure.ac (GST_HAVE_GLIB_2_8_DEFINE): Make the availability of GLib 2.8 public, so we can know which refcount to check in tests. * gst/gstobject.c: Use the GST_HAVE_GLIB_2_8 define. (gst_object_init): Only set the gst refcount if we're going ahead with the refcount hack.
Diffstat (limited to 'gst')
-rw-r--r--gst/gstconfig.h.in4
-rw-r--r--gst/gstelementfactory.c19
-rw-r--r--gst/gstobject.c4
-rw-r--r--gst/gstobject.h7
4 files changed, 28 insertions, 6 deletions
diff --git a/gst/gstconfig.h.in b/gst/gstconfig.h.in
index 0647d5407..70b60ebf4 100644
--- a/gst/gstconfig.h.in
+++ b/gst/gstconfig.h.in
@@ -112,6 +112,10 @@
/* whether or not the CPU supports unaligned access */
@GST_HAVE_UNALIGNED_ACCESS_DEFINE@
+/* whether or not we are using glib 2.8 api, e.g. atomic gobject
+ refcounting */
+@GST_HAVE_GLIB_2_8_DEFINE@
+
/***** Deal with XML stuff, we have to handle both loadsave and registry *****/
#if (! (defined(GST_DISABLE_LOADSAVE) && defined(GST_DISABLE_REGISTRY)) )
diff --git a/gst/gstelementfactory.c b/gst/gstelementfactory.c
index 5afb15cdb..c545b62f5 100644
--- a/gst/gstelementfactory.c
+++ b/gst/gstelementfactory.c
@@ -349,15 +349,27 @@ gst_element_factory_create (GstElementFactory * factory, const gchar * name)
{
GstElement *element;
GstElementClass *oclass;
+ GstElementFactory *newfactory;
g_return_val_if_fail (factory != NULL, NULL);
- factory =
+ gst_object_ref (factory);
+
+ newfactory =
GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
(factory)));
- if (factory == NULL) {
- GST_DEBUG ("warning: loading the plugin for this factory returned NULL");
+ if (newfactory == NULL) {
+ /* it could be factory is invalid. with ref-eating functions nothing is
+ certain! */
+ GST_WARNING ("loading the plugin for factory %p returned NULL", factory);
return NULL;
+ } else if (newfactory != factory) {
+ /* gst_plugin_feature_load ate the ref we added to the factory */
+ factory = newfactory;
+ } else {
+ /* strip off our extra ref */
+ gst_object_unref (factory);
+ factory = newfactory;
}
if (name)
@@ -392,7 +404,6 @@ gst_element_factory_create (GstElementFactory * factory, const gchar * name)
gst_object_set_name (GST_OBJECT (element), name);
GST_DEBUG ("created \"%s\"", GST_PLUGIN_FEATURE_NAME (factory));
- gst_object_unref (factory);
return element;
}
diff --git a/gst/gstobject.c b/gst/gstobject.c
index 91bd7aa95..79cc89945 100644
--- a/gst/gstobject.c
+++ b/gst/gstobject.c
@@ -33,7 +33,7 @@
#endif
#define DEBUG_REFCOUNT
-#ifndef HAVE_GLIB_2_8
+#ifndef GST_HAVE_GLIB_2_8
#define REFCOUNT_HACK
#endif
@@ -218,7 +218,9 @@ gst_object_init (GTypeInstance * instance, gpointer g_class)
object->parent = NULL;
object->name = NULL;
GST_CAT_LOG_OBJECT (GST_CAT_REFCOUNTING, object, "%p new", object);
+#ifdef REFCOUNT_HACK
gst_atomic_int_set (&object->refcount, 1);
+#endif
PATCH_REFCOUNT (object);
object->flags = 0;
diff --git a/gst/gstobject.h b/gst/gstobject.h
index 3f6cb6727..31e2645d3 100644
--- a/gst/gstobject.h
+++ b/gst/gstobject.h
@@ -55,8 +55,13 @@ typedef enum
GST_OBJECT_FLAG_LAST = 4
} GstObjectFlags;
+#ifdef GST_HAVE_GLIB_2_8
+#define GST_OBJECT_REFCOUNT(obj) (((GObject*)(obj))->ref_count)
+#define GST_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&((GObject*)(obj))->ref_count))
+#else
#define GST_OBJECT_REFCOUNT(obj) ((GST_OBJECT_CAST(obj))->refcount)
#define GST_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&(GST_OBJECT_CAST(obj))->refcount))
+#endif /* GST_HAVE_GLIB_2_8 */
/* we do a GST_OBJECT_CAST to avoid type checking, better call these
* function with a valid object! */
@@ -84,7 +89,7 @@ struct _GstObject {
GObject object;
/*< public >*/
- gint refcount;
+ gint refcount; /* only used ifndef GST_HAVE_GLIB_0_8 */
/*< public >*/ /* with LOCK */
GMutex *lock; /* object LOCK */