From 3fab00b46aad44e0375988fd61e13e900fa114a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 13 Dec 2016 20:51:17 +0200 Subject: [PATCH] queue/queue2: Protect against spurious condition variable wakeups Make sure that we only wake up when we have to flush, or when this specific query was handled. https://bugzilla.gnome.org/show_bug.cgi?id=776039 --- plugins/elements/gstqueue.c | 6 +++++- plugins/elements/gstqueue.h | 1 + plugins/elements/gstqueue2.c | 6 +++++- plugins/elements/gstqueue2.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c index 1f0c09cf15..c6d66ebf27 100644 --- a/plugins/elements/gstqueue.c +++ b/plugins/elements/gstqueue.c @@ -1045,7 +1045,10 @@ gst_queue_handle_sink_query (GstPad * pad, GstObject * parent, GstQuery * query) qitem.size = 0; gst_queue_array_push_tail_struct (queue->queue, &qitem); GST_QUEUE_SIGNAL_ADD (queue); - g_cond_wait (&queue->query_handled, &queue->qlock); + while (queue->srcresult == GST_FLOW_OK && + queue->last_handled_query != query) + g_cond_wait (&queue->query_handled, &queue->qlock); + queue->last_handled_query = NULL; if (queue->srcresult != GST_FLOW_OK) goto out_flushing; res = queue->last_query; @@ -1443,6 +1446,7 @@ next: ret = gst_pad_peer_query (queue->srcpad, query); GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing_query); queue->last_query = ret; + queue->last_handled_query = query; g_cond_signal (&queue->query_handled); GST_CAT_LOG_OBJECT (queue_dataflow, queue, "did query %p, return %d", query, queue->last_query); diff --git a/plugins/elements/gstqueue.h b/plugins/elements/gstqueue.h index 4c7491c33e..2a9cb3612a 100644 --- a/plugins/elements/gstqueue.h +++ b/plugins/elements/gstqueue.h @@ -135,6 +135,7 @@ struct _GstQueue { GCond query_handled; gboolean last_query; + GstQuery *last_handled_query; gboolean flush_on_eos; /* flush on EOS */ }; diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c index 4c670a024b..3a878e0d1f 100644 --- a/plugins/elements/gstqueue2.c +++ b/plugins/elements/gstqueue2.c @@ -2642,7 +2642,10 @@ gst_queue2_handle_sink_query (GstPad * pad, GstObject * parent, GST_QUEUE2_ITEM_TYPE_QUERY); STATUS (queue, queue->sinkpad, "wait for QUERY"); - g_cond_wait (&queue->query_handled, &queue->qlock); + while (queue->sinkresult == GST_FLOW_OK && + queue->last_handled_query != query) + g_cond_wait (&queue->query_handled, &queue->qlock); + queue->last_handled_query = NULL; if (queue->sinkresult != GST_FLOW_OK) goto out_flushing; res = queue->last_query; @@ -2970,6 +2973,7 @@ next: GstQuery *query = GST_QUERY_CAST (data); GST_LOG_OBJECT (queue->srcpad, "Peering query %p", query); + queue->last_handled_query = query; queue->last_query = gst_pad_peer_query (queue->srcpad, query); GST_LOG_OBJECT (queue->srcpad, "Peered query"); GST_CAT_LOG_OBJECT (queue_dataflow, queue, diff --git a/plugins/elements/gstqueue2.h b/plugins/elements/gstqueue2.h index a1b94a7865..34e3abaf6a 100644 --- a/plugins/elements/gstqueue2.h +++ b/plugins/elements/gstqueue2.h @@ -102,6 +102,7 @@ struct _GstQueue2 GCond query_handled; gboolean last_query; /* result of last serialized query */ + GstQuery *last_handled_query; GstQueue2Size cur_level; /* currently in the queue */ GstQueue2Size max_level; /* max. amount of data allowed in the queue */