Commit d4199704 authored by Shixin Zeng's avatar Shixin Zeng Committed by Sebastian Dröge

gst: make _get_type() in gst/* thread safe

This is not really necessary here because everything is
initialized from gst_init() already but using G_DEFINE_TYPE()
removes some copy&paste boilerplate code.
parent 98da78ed
......@@ -165,7 +165,8 @@ struct _GstBufferListIterator
};
static GType _gst_buffer_list_type = 0;
static GstMiniObjectClass *parent_class = NULL;
G_DEFINE_TYPE (GstBufferList, gst_buffer_list, GST_TYPE_MINI_OBJECT);
void
_gst_buffer_list_initialize (void)
......@@ -174,11 +175,8 @@ _gst_buffer_list_initialize (void)
}
static void
gst_buffer_list_init (GTypeInstance * instance, gpointer g_class)
gst_buffer_list_init (GstBufferList * list)
{
GstBufferList *list;
list = (GstBufferList *) instance;
list->buffers = NULL;
GST_LOG ("init %p", list);
......@@ -202,7 +200,8 @@ gst_buffer_list_finalize (GstBufferList * list)
}
g_list_free (list->buffers);
parent_class->finalize (GST_MINI_OBJECT_CAST (list));
GST_MINI_OBJECT_CLASS (gst_buffer_list_parent_class)->finalize
(GST_MINI_OBJECT_CAST (list));
}
static GstBufferList *
......@@ -231,12 +230,8 @@ _gst_buffer_list_copy (GstBufferList * list)
}
static void
gst_buffer_list_class_init (gpointer g_class, gpointer class_data)
gst_buffer_list_class_init (GstBufferListClass * list_class)
{
GstBufferListClass *list_class = GST_BUFFER_LIST_CLASS (g_class);
parent_class = g_type_class_peek_parent (g_class);
list_class->mini_object_class.copy =
(GstMiniObjectCopyFunction) _gst_buffer_list_copy;
list_class->mini_object_class.finalize =
......@@ -420,30 +415,6 @@ gst_buffer_list_get (GstBufferList * list, guint group, guint idx)
return NULL;
}
GType
gst_buffer_list_get_type (void)
{
if (G_UNLIKELY (_gst_buffer_list_type == 0)) {
static const GTypeInfo buffer_list_info = {
sizeof (GstBufferListClass),
NULL,
NULL,
gst_buffer_list_class_init,
NULL,
NULL,
sizeof (GstBufferList),
0,
gst_buffer_list_init,
NULL
};
_gst_buffer_list_type = g_type_register_static (GST_TYPE_MINI_OBJECT,
"GstBufferList", &buffer_list_info, 0);
}
return _gst_buffer_list_type;
}
/**
* gst_buffer_list_iterate:
* @list: a #GstBufferList
......
......@@ -68,9 +68,10 @@ static void gst_mini_object_finalize (GstMiniObject * obj);
GType
gst_mini_object_get_type (void)
{
static GType _gst_mini_object_type = 0;
static volatile GType _gst_mini_object_type = 0;
if (G_UNLIKELY (_gst_mini_object_type == 0)) {
if (g_once_init_enter (&_gst_mini_object_type)) {
GType _type;
static const GTypeValueTable value_table = {
gst_value_mini_object_init,
gst_value_mini_object_free,
......@@ -102,14 +103,14 @@ gst_mini_object_get_type (void)
G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
};
_gst_mini_object_type = g_type_fundamental_next ();
g_type_register_fundamental (_gst_mini_object_type, "GstMiniObject",
_type = g_type_fundamental_next ();
g_type_register_fundamental (_type, "GstMiniObject",
&mini_object_info, &mini_object_fundamental_info, G_TYPE_FLAG_ABSTRACT);
#ifndef GST_DISABLE_TRACE
_gst_mini_object_trace =
gst_alloc_trace_register (g_type_name (_gst_mini_object_type));
_gst_mini_object_trace = gst_alloc_trace_register (g_type_name (_type));
#endif
g_once_init_leave (&_gst_mini_object_type, _type);
}
return _gst_mini_object_type;
......
......@@ -4178,13 +4178,15 @@ static GTypeFundamentalInfo _finfo = {
#define FUNC_VALUE_GET_TYPE(type, name) \
GType gst_ ## type ## _get_type (void) \
{ \
static GType gst_ ## type ## _type = 0; \
static volatile GType gst_ ## type ## _type = 0; \
\
if (G_UNLIKELY (gst_ ## type ## _type == 0)) { \
if (g_once_init_enter (&gst_ ## type ## _type)) { \
GType _type; \
_info.value_table = & _gst_ ## type ## _value_table; \
gst_ ## type ## _type = g_type_register_fundamental ( \
_type = g_type_register_fundamental ( \
g_type_fundamental_next (), \
name, &_info, &_finfo, 0); \
g_once_init_leave(&gst_ ## type ## _type, _type); \
} \
\
return gst_ ## type ## _type; \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment