gst/: Use GSlice when the glib we build against is >= 2.10

Original commit message from CVS:
* gst/gstcaps.c: (gst_caps_new_empty), (_gst_caps_free),
(gst_caps_unref), (gst_static_caps_get),
(gst_caps_append_structure):
* gst/gstclock.c: (gst_clock_entry_new), (_gst_clock_id_free):
Use GSlice when the glib we build against is >= 2.10
This commit is contained in:
Wim Taymans 2006-07-03 16:57:54 +00:00
parent a888719a87
commit 8fbd33910c
3 changed files with 50 additions and 21 deletions

View file

@ -1,3 +1,11 @@
2006-07-03 Wim Taymans <wim@fluendo.com>
* gst/gstcaps.c: (gst_caps_new_empty), (_gst_caps_free),
(gst_caps_unref), (gst_static_caps_get),
(gst_caps_append_structure):
* gst/gstclock.c: (gst_clock_entry_new), (_gst_clock_id_free):
Use GSlice when the glib we build against is >= 2.10
2006-07-03 Wim Taymans <wim@fluendo.com>
* gst/gstelement.c: (gst_element_pads_activate):

View file

@ -91,6 +91,13 @@
#define IS_WRITABLE(caps) \
(g_atomic_int_get (&(caps)->refcount) == 1)
#if GLIB_CHECK_VERSION (2, 10, 0)
#define ALLOC_CAPS() g_slice_new (GstCaps)
#define FREE_CAPS(caps) g_slice_free (GstCaps, caps)
#else
#define ALLOC_CAPS() g_new (GstCaps, 1)
#define FREE_CAPS(caps) g_free (caps)
#endif
static void gst_caps_transform_to_string (const GValue * src_value,
GValue * dest_value);
@ -129,10 +136,11 @@ gst_caps_get_type (void)
GstCaps *
gst_caps_new_empty (void)
{
GstCaps *caps = g_new0 (GstCaps, 1);
GstCaps *caps = ALLOC_CAPS ();
g_atomic_int_inc (&caps->refcount);
caps->type = GST_TYPE_CAPS;
caps->refcount = 1;
caps->flags = 0;
caps->structs = g_ptr_array_new ();
#ifdef DEBUG_REFCOUNT
@ -294,7 +302,7 @@ _gst_caps_free (GstCaps * caps)
#ifdef USE_POISONING
memset (caps, 0xff, sizeof (GstCaps));
#endif
g_free (caps);
FREE_CAPS (caps);
}
/**
@ -384,9 +392,8 @@ gst_caps_unref (GstCaps * caps)
g_return_if_fail (GST_CAPS_REFCOUNT_VALUE (caps) > 0);
/* if we ended up with the refcount at zero, free the caps */
if (g_atomic_int_dec_and_test (&caps->refcount)) {
if (G_UNLIKELY (g_atomic_int_dec_and_test (&caps->refcount)))
_gst_caps_free (caps);
}
}
GType
@ -414,33 +421,39 @@ gst_static_caps_get_type (void)
GstCaps *
gst_static_caps_get (GstStaticCaps * static_caps)
{
GstCaps *caps = (GstCaps *) static_caps;
gboolean ret;
GstCaps *caps;
g_return_val_if_fail (static_caps != NULL, NULL);
caps = (GstCaps *) static_caps;
if (caps->type == 0) {
if (static_caps->string == NULL) {
g_warning ("static caps is NULL");
return NULL;
}
if (G_UNLIKELY (static_caps->string == NULL))
goto no_string;
caps->type = GST_TYPE_CAPS;
/* initialize the caps to a refcount of 1 so the caps can be writable... */
gst_atomic_int_set (&caps->refcount, 1);
caps->structs = g_ptr_array_new ();
ret = gst_caps_from_string_inplace (caps, static_caps->string);
if (!ret) {
/* convert to string */
if (G_UNLIKELY (!gst_caps_from_string_inplace (caps, static_caps->string)))
g_critical ("Could not convert static caps \"%s\"", static_caps->string);
}
}
/* ref the caps, makes it not writable */
gst_caps_ref (caps);
return caps;
/* ERRORS */
no_string:
{
g_warning ("static caps string is NULL");
return NULL;
}
}
/* manipulation */
static GstStructure *
gst_caps_remove_and_get_structure (GstCaps * caps, guint idx)
{
@ -506,7 +519,7 @@ gst_caps_append_structure (GstCaps * caps, GstStructure * structure)
g_return_if_fail (GST_IS_CAPS (caps));
g_return_if_fail (IS_WRITABLE (caps));
if (structure) {
if (G_LIKELY (structure)) {
g_return_if_fail (structure->parent_refcount == NULL);
#if 0
#ifdef USE_POISONING

View file

@ -116,6 +116,14 @@
static GstAllocTrace *_gst_clock_entry_trace;
#endif
#if GLIB_CHECK_VERSION (2, 10, 0)
#define ALLOC_ENTRY() g_slice_new (GstClockEntry)
#define FREE_ENTRY(entry) g_slice_free (GstClockEntry, entry)
#else
#define ALLOC_ENTRY() g_new (GstClockEntry, 1)
#define FREE_ENTRY(entry) g_free (entry)
#endif
/* #define DEBUGGING_ENABLED */
#define DEFAULT_STATS FALSE
@ -154,9 +162,7 @@ gst_clock_entry_new (GstClock * clock, GstClockTime time,
{
GstClockEntry *entry;
/* FIXME, use g_slice, we do this a lot and potentially from
* different threads. */
entry = g_new0 (GstClockEntry, 1);
entry = ALLOC_ENTRY ();
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_new (_gst_clock_entry_trace, entry);
#endif
@ -165,10 +171,12 @@ gst_clock_entry_new (GstClock * clock, GstClockTime time,
gst_atomic_int_set (&entry->refcount, 1);
entry->clock = clock;
entry->type = type;
entry->time = time;
entry->interval = interval;
entry->type = type;
entry->status = GST_CLOCK_BUSY;
entry->func = NULL;
entry->user_data = NULL;
return (GstClockID) entry;
}
@ -203,7 +211,7 @@ _gst_clock_id_free (GstClockID id)
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_free (_gst_clock_entry_trace, id);
#endif
g_free (id);
FREE_ENTRY (id);
}
/**