mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-16 21:36:35 +00:00
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.
This commit is contained in:
parent
98da78ed2a
commit
d41997040b
3 changed files with 18 additions and 44 deletions
|
@ -165,7 +165,8 @@ struct _GstBufferListIterator
|
||||||
};
|
};
|
||||||
|
|
||||||
static GType _gst_buffer_list_type = 0;
|
static GType _gst_buffer_list_type = 0;
|
||||||
static GstMiniObjectClass *parent_class = NULL;
|
|
||||||
|
G_DEFINE_TYPE (GstBufferList, gst_buffer_list, GST_TYPE_MINI_OBJECT);
|
||||||
|
|
||||||
void
|
void
|
||||||
_gst_buffer_list_initialize (void)
|
_gst_buffer_list_initialize (void)
|
||||||
|
@ -174,11 +175,8 @@ _gst_buffer_list_initialize (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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;
|
list->buffers = NULL;
|
||||||
|
|
||||||
GST_LOG ("init %p", list);
|
GST_LOG ("init %p", list);
|
||||||
|
@ -202,7 +200,8 @@ gst_buffer_list_finalize (GstBufferList * list)
|
||||||
}
|
}
|
||||||
g_list_free (list->buffers);
|
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 *
|
static GstBufferList *
|
||||||
|
@ -231,12 +230,8 @@ _gst_buffer_list_copy (GstBufferList * list)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 =
|
list_class->mini_object_class.copy =
|
||||||
(GstMiniObjectCopyFunction) _gst_buffer_list_copy;
|
(GstMiniObjectCopyFunction) _gst_buffer_list_copy;
|
||||||
list_class->mini_object_class.finalize =
|
list_class->mini_object_class.finalize =
|
||||||
|
@ -420,30 +415,6 @@ gst_buffer_list_get (GstBufferList * list, guint group, guint idx)
|
||||||
return NULL;
|
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:
|
* gst_buffer_list_iterate:
|
||||||
* @list: a #GstBufferList
|
* @list: a #GstBufferList
|
||||||
|
|
|
@ -68,9 +68,10 @@ static void gst_mini_object_finalize (GstMiniObject * obj);
|
||||||
GType
|
GType
|
||||||
gst_mini_object_get_type (void)
|
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 = {
|
static const GTypeValueTable value_table = {
|
||||||
gst_value_mini_object_init,
|
gst_value_mini_object_init,
|
||||||
gst_value_mini_object_free,
|
gst_value_mini_object_free,
|
||||||
|
@ -102,14 +103,14 @@ gst_mini_object_get_type (void)
|
||||||
G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
|
G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
|
||||||
};
|
};
|
||||||
|
|
||||||
_gst_mini_object_type = g_type_fundamental_next ();
|
_type = g_type_fundamental_next ();
|
||||||
g_type_register_fundamental (_gst_mini_object_type, "GstMiniObject",
|
g_type_register_fundamental (_type, "GstMiniObject",
|
||||||
&mini_object_info, &mini_object_fundamental_info, G_TYPE_FLAG_ABSTRACT);
|
&mini_object_info, &mini_object_fundamental_info, G_TYPE_FLAG_ABSTRACT);
|
||||||
|
|
||||||
#ifndef GST_DISABLE_TRACE
|
#ifndef GST_DISABLE_TRACE
|
||||||
_gst_mini_object_trace =
|
_gst_mini_object_trace = gst_alloc_trace_register (g_type_name (_type));
|
||||||
gst_alloc_trace_register (g_type_name (_gst_mini_object_type));
|
|
||||||
#endif
|
#endif
|
||||||
|
g_once_init_leave (&_gst_mini_object_type, _type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _gst_mini_object_type;
|
return _gst_mini_object_type;
|
||||||
|
|
|
@ -4178,13 +4178,15 @@ static GTypeFundamentalInfo _finfo = {
|
||||||
#define FUNC_VALUE_GET_TYPE(type, name) \
|
#define FUNC_VALUE_GET_TYPE(type, name) \
|
||||||
GType gst_ ## type ## _get_type (void) \
|
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; \
|
_info.value_table = & _gst_ ## type ## _value_table; \
|
||||||
gst_ ## type ## _type = g_type_register_fundamental ( \
|
_type = g_type_register_fundamental ( \
|
||||||
g_type_fundamental_next (), \
|
g_type_fundamental_next (), \
|
||||||
name, &_info, &_finfo, 0); \
|
name, &_info, &_finfo, 0); \
|
||||||
|
g_once_init_leave(&gst_ ## type ## _type, _type); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return gst_ ## type ## _type; \
|
return gst_ ## type ## _type; \
|
||||||
|
|
Loading…
Reference in a new issue