From e46f846c1f561471145e9606b641cc27c647e20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 25 Apr 2008 10:01:46 +0000 Subject: [PATCH] Ref some more classes in gst_init() to work around thread-safety issues in pre-2.16 GLibs, and add basic unit test. Original commit message from CVS: * gst/gst.c: (init_post), (gst_deinit): * tests/check/gst/gstpipeline.c: (GST_START_TEST), (pipeline_thread), (test_concurrent_create), (gst_pipeline_suite): Ref some more classes in gst_init() to work around thread-safety issues in pre-2.16 GLibs, and add basic unit test. --- ChangeLog | 8 +++++++ gst/gst.c | 4 ++++ tests/check/gst/gstpipeline.c | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/ChangeLog b/ChangeLog index d110a36720..7a94619eb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-04-25 Tim-Philipp Müller + + * gst/gst.c: (init_post), (gst_deinit): + * tests/check/gst/gstpipeline.c: (GST_START_TEST), (pipeline_thread), + (test_concurrent_create), (gst_pipeline_suite): + Ref some more classes in gst_init() to work around thread-safety + issues in pre-2.16 GLibs, and add basic unit test. + 2008-04-25 Wim Taymans * libs/gst/base/gstbasesink.c: (gst_base_sink_query_latency), diff --git a/gst/gst.c b/gst/gst.c index 7c89abb737..9006cc773e 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -983,6 +983,8 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, g_type_class_ref (gst_element_get_type ()); g_type_class_ref (gst_type_find_factory_get_type ()); g_type_class_ref (gst_bin_get_type ()); + g_type_class_ref (gst_bus_get_type ()); + g_type_class_ref (gst_task_get_type ()); #ifndef GST_DISABLE_INDEX g_type_class_ref (gst_index_factory_get_type ()); @@ -1325,6 +1327,8 @@ gst_deinit (void) g_type_class_unref (g_type_class_peek (gst_element_get_type ())); g_type_class_unref (g_type_class_peek (gst_type_find_factory_get_type ())); g_type_class_unref (g_type_class_peek (gst_bin_get_type ())); + g_type_class_unref (g_type_class_peek (gst_bus_get_type ())); + g_type_class_unref (g_type_class_peek (gst_task_get_type ())); #ifndef GST_DISABLE_INDEX g_type_class_unref (g_type_class_peek (gst_index_factory_get_type ())); #endif /* GST_DISABLE_INDEX */ diff --git a/tests/check/gst/gstpipeline.c b/tests/check/gst/gstpipeline.c index c344b03a8a..d04a2269c3 100644 --- a/tests/check/gst/gstpipeline.c +++ b/tests/check/gst/gstpipeline.c @@ -18,8 +18,12 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include +#include #define WAIT_TIME (300 * GST_MSECOND) @@ -487,6 +491,42 @@ GST_START_TEST (test_base_time) GST_END_TEST; +static gpointer +pipeline_thread (gpointer data) +{ + GstElement *pipeline, *src, *sink; + + src = gst_element_factory_make ("fakesrc", NULL); + g_object_set (src, "num-buffers", 20, NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_object_set (sink, "sync", TRUE, NULL); + pipeline = gst_pipeline_new (NULL); + gst_bin_add (GST_BIN (pipeline), src); + gst_bin_add (GST_BIN (pipeline), sink); + gst_element_link (src, sink); + gst_element_set_state (pipeline, GST_STATE_PLAYING); + g_usleep (G_USEC_PER_SEC / 10); + gst_element_set_state (pipeline, GST_STATE_NULL); + gst_object_unref (pipeline); + return NULL; +} + +GST_START_TEST (test_concurrent_create) +{ + GThread *threads[30]; + int i; + + for (i = 0; i < G_N_ELEMENTS (threads); ++i) { + threads[i] = g_thread_create (pipeline_thread, NULL, TRUE, NULL); + } + for (i = 0; i < G_N_ELEMENTS (threads); ++i) { + if (threads[i]) + g_thread_join (threads[i]); + } +} + +GST_END_TEST; + static Suite * gst_pipeline_suite (void) { @@ -502,6 +542,7 @@ gst_pipeline_suite (void) tcase_add_test (tc_chain, test_get_bus); tcase_add_test (tc_chain, test_bus); tcase_add_test (tc_chain, test_base_time); + tcase_add_test (tc_chain, test_concurrent_create); return s; }