tests: make *_get_type() in tests thread safe

Even if it shouldn't be needed here. See #623491.
This commit is contained in:
Shixin Zeng 2010-07-20 09:25:20 -05:00 committed by Tim-Philipp Müller
parent 9d4caf8d8c
commit f6b0200026
3 changed files with 17 additions and 11 deletions

View file

@ -42,15 +42,16 @@ struct _GstFakeObjectClass
GstObjectClass parent_class; GstObjectClass parent_class;
}; };
static GType _gst_fake_object_type = 0;
//static GstObjectClass *parent_class = NULL; //static GstObjectClass *parent_class = NULL;
//static guint gst_fake_object_signals[LAST_SIGNAL] = { 0 }; //static guint gst_fake_object_signals[LAST_SIGNAL] = { 0 };
static GType static GType
gst_fake_object_get_type (void) gst_fake_object_get_type (void)
{ {
if (!_gst_fake_object_type) { static volatile gsize fake_object_type = 0;
if (g_once_init_enter (&fake_object_type)) {
GType type;
static const GTypeInfo fake_object_info = { static const GTypeInfo fake_object_info = {
sizeof (GstFakeObjectClass), sizeof (GstFakeObjectClass),
NULL, //gst_fake_object_base_class_init, NULL, //gst_fake_object_base_class_init,
@ -64,10 +65,11 @@ gst_fake_object_get_type (void)
NULL NULL
}; };
_gst_fake_object_type = g_type_register_static (GST_TYPE_OBJECT, type = g_type_register_static (GST_TYPE_OBJECT,
"GstFakeObject", &fake_object_info, 0); "GstFakeObject", &fake_object_info, 0);
g_once_init_leave (&fake_object_type, type);
} }
return _gst_fake_object_type; return fake_object_type;
} }
#ifndef HAVE_OSX #ifndef HAVE_OSX

View file

@ -112,9 +112,10 @@ gst_preset_test_base_init (GstPresetTestClass * klass)
static GType static GType
gst_preset_test_get_type (void) gst_preset_test_get_type (void)
{ {
static GType type = 0; static volatile gsize preset_test_type = 0;
if (type == 0) { if (g_once_init_enter (&preset_test_type)) {
GType type;
const GTypeInfo info = { const GTypeInfo info = {
sizeof (GstPresetTestClass), sizeof (GstPresetTestClass),
(GBaseInitFunc) gst_preset_test_base_init, /* base_init */ (GBaseInitFunc) gst_preset_test_base_init, /* base_init */
@ -134,8 +135,9 @@ gst_preset_test_get_type (void)
}; };
type = g_type_register_static (GST_TYPE_ELEMENT, "GstPresetTest", &info, 0); type = g_type_register_static (GST_TYPE_ELEMENT, "GstPresetTest", &info, 0);
g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_interface_info); g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_interface_info);
g_once_init_leave (&preset_test_type, type);
} }
return type; return preset_test_type;
} }
static gboolean static gboolean

View file

@ -191,9 +191,10 @@ gst_test_mono_source_base_init (GstTestMonoSourceClass * klass)
static GType static GType
gst_test_mono_source_get_type (void) gst_test_mono_source_get_type (void)
{ {
static GType type = 0; static volatile gsize test_mono_source_type = 0;
if (type == 0) { if (g_once_init_enter (&test_mono_source_type)) {
GType type;
static const GTypeInfo info = { static const GTypeInfo info = {
(guint16) sizeof (GstTestMonoSourceClass), (guint16) sizeof (GstTestMonoSourceClass),
(GBaseInitFunc) gst_test_mono_source_base_init, // base_init (GBaseInitFunc) gst_test_mono_source_base_init, // base_init
@ -209,8 +210,9 @@ gst_test_mono_source_get_type (void)
type = type =
g_type_register_static (GST_TYPE_ELEMENT, "GstTestMonoSource", &info, g_type_register_static (GST_TYPE_ELEMENT, "GstTestMonoSource", &info,
0); 0);
g_once_init_leave (&test_mono_source_type, type);
} }
return type; return test_mono_source_type;
} }
/* so we don't have to paste the gst_element_register into 50 places below */ /* so we don't have to paste the gst_element_register into 50 places below */