tests/webrtc: move bus thread creation earlier
authorMatthew Waters <matthew@centricular.com>
Tue, 5 May 2020 04:33:34 +0000 (14:33 +1000)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 6 May 2020 02:53:27 +0000 (02:53 +0000)
Fixes a small deadlock race where the bus watch GSource could execute before
the unlock mutex GSource.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1240>

tests/check/elements/webrtcbin.c

index 77e2a8e..3473ede 100644 (file)
@@ -499,6 +499,13 @@ test_webrtc_new (void)
   g_mutex_init (&ret->lock);
   g_cond_init (&ret->cond);
 
+  ret->thread = g_thread_new ("test-webrtc", (GThreadFunc) _bus_thread, ret);
+
+  g_mutex_lock (&ret->lock);
+  while (!ret->loop)
+    g_cond_wait (&ret->cond, &ret->lock);
+  g_mutex_unlock (&ret->lock);
+
   ret->bus1 = gst_bus_new ();
   ret->bus2 = gst_bus_new ();
   gst_bus_add_watch (ret->bus1, (GstBusFunc) _bus_watch, ret);
@@ -537,13 +544,6 @@ test_webrtc_new (void)
   g_signal_connect_swapped (ret->webrtc2, "notify::ice-connection-state",
       G_CALLBACK (_broadcast), ret);
 
-  ret->thread = g_thread_new ("test-webrtc", (GThreadFunc) _bus_thread, ret);
-
-  g_mutex_lock (&ret->lock);
-  while (!ret->loop)
-    g_cond_wait (&ret->cond, &ret->lock);
-  g_mutex_unlock (&ret->lock);
-
   return ret;
 }