Ref some more classes in gst_init() to work around thread-safety issues in pre-2...
authorTim-Philipp Müller <tim@centricular.net>
Fri, 25 Apr 2008 10:01:46 +0000 (10:01 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Fri, 25 Apr 2008 10:01:46 +0000 (10:01 +0000)
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
gst/gst.c
tests/check/gst/gstpipeline.c

index d110a36..7a94619 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-04-25  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * 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  <wim.taymans@collabora.co.uk>
 
        * libs/gst/base/gstbasesink.c: (gst_base_sink_query_latency),
index 7c89abb..9006cc7 100644 (file)
--- 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 */
index c344b03..d04a226 100644 (file)
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <gst/check/gstcheck.h>
+#include <gst/gst.h>
 
 #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;
 }