[Bug 765728] adaptivedemux: Segfault since "use realtime_clock for waiting for a condition" commit

GStreamer (GNOME Bugzilla) bugzilla at gnome.org
Fri Apr 29 09:33:40 UTC 2016


https://bugzilla.gnome.org/show_bug.cgi?id=765728

--- Comment #18 from A Ashley <bugzilla at ashley-family.net> ---
+static gboolean
+gst_adaptive_demux_wait_until (GstClock * clock, GCond * cond, GMutex * mutex,
+    GstClockTime end_time)
+{
+  GstAdaptiveDemuxTimer timer;
+  GstClockReturn res;
+
+  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (end_time))) {
+    /* for an invalid time, gst_clock_id_wait_async will try to call
+     * gst_adaptive_demux_clock_callback from the current thread.
+     * It still holds the mutex while doing that, so it will deadlock.
+     * g_cond_wait_until would return immediately with false, so we'll do the
s
ame.
+     */
+    return FALSE;
+  }
+  timer.fired = FALSE;
+  timer.cond = cond;
+  timer.mutex = mutex;
+  timer.clock_id = gst_clock_new_single_shot_id (clock, end_time);
+  res =
+      gst_clock_id_wait_async (timer.clock_id,
+      gst_adaptive_demux_clock_callback, &timer, NULL);

What happens if end_time is already in the past? Will the callback get called
using this thread? If so, that would cause a deadlock as the mutex is already
held.

+  /* clock does not support asynchronously wait. Assert and return */
+  if (res == GST_CLOCK_UNSUPPORTED) {
+    gst_clock_id_unref (timer.clock_id);
+    g_return_val_if_reached (TRUE);
+  }
+  /* the gst_adaptive_demux_clock_callback will signal the
+     cond when the clock's single shot timer fires */
+  g_cond_wait (cond, mutex);

If the condition has been signalled by another thread (e.g. one wanting to stop
the task) should gst_clock_id_unschedule() be called? Could the callback fire
after this function has returned?

+  gst_clock_id_unref (timer.clock_id);
+  return !timer.fired;
+}

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.


More information about the gstreamer-bugs mailing list