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
This commit is contained in:
Sebastian Dröge 2016-12-13 20:51:17 +02:00
parent 33c239828b
commit 3fab00b46a
4 changed files with 12 additions and 2 deletions

View file

@ -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);

View file

@ -135,6 +135,7 @@ struct _GstQueue {
GCond query_handled;
gboolean last_query;
GstQuery *last_handled_query;
gboolean flush_on_eos; /* flush on EOS */
};

View file

@ -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,

View file

@ -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 */