systemclock: Use a flag while waiting for the async thread to start
authorSebastian Dröge <sebastian@centricular.com>
Thu, 28 Nov 2024 13:25:47 +0000 (15:25 +0200)
committerBackport Bot <gitlab-backport-bot@gstreamer-foundation.org>
Mon, 2 Dec 2024 10:00:27 +0000 (10:00 +0000)
Otherwise there can be spurious wakeups.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8019>

subprojects/gstreamer/gst/gstsystemclock.c

index 2b02bddd3f3e11b8918c2134b7f5597384a2dfa2..32b577cb614022c55e374d206f7cfb7108484c4f 100644 (file)
@@ -571,6 +571,7 @@ ensure_entry_initialized (GstClockEntryImpl * entry_impl)
 struct _GstSystemClockPrivate
 {
   GThread *thread;              /* thread for async notify */
+  gboolean starting;
   gboolean stopping;
 
   GList *entries;
@@ -875,6 +876,7 @@ gst_system_clock_async_thread (GstClock * clock)
   GST_CAT_DEBUG_OBJECT (GST_CAT_CLOCK, clock, "enter system clock thread");
   GST_SYSTEM_CLOCK_LOCK (clock);
   /* signal spinup */
+  priv->starting = FALSE;
   GST_SYSTEM_CLOCK_BROADCAST (clock);
   /* now enter our (almost) infinite loop */
   while (!priv->stopping) {
@@ -1316,6 +1318,7 @@ gst_system_clock_start_async (GstSystemClock * clock)
   if (G_LIKELY (priv->thread != NULL))
     return TRUE;                /* Thread already running. Nothing to do */
 
+  priv->starting = TRUE;
   priv->thread = g_thread_try_new ("GstSystemClock",
       (GThreadFunc) gst_system_clock_async_thread, clock, &error);
 
@@ -1323,13 +1326,15 @@ gst_system_clock_start_async (GstSystemClock * clock)
     goto no_thread;
 
   /* wait for it to spin up */
-  GST_SYSTEM_CLOCK_WAIT (clock);
+  while (priv->starting)
+    GST_SYSTEM_CLOCK_WAIT (clock);
 
   return TRUE;
 
   /* ERRORS */
 no_thread:
   {
+    priv->starting = FALSE;
     g_warning ("could not create async clock thread: %s", error->message);
     g_error_free (error);
   }