From a62815326005cf4c130bec933753d25c68b5a97e Mon Sep 17 00:00:00 2001 From: Josep Torra Date: Tue, 24 Sep 2013 18:48:24 +0200 Subject: [PATCH] examples: fix another race condition Fix a race condition that caused randome deadlocks on EOS. --- examples/egl/testegl.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/egl/testegl.c b/examples/egl/testegl.c index b20c91e..7886483 100644 --- a/examples/egl/testegl.c +++ b/examples/egl/testegl.c @@ -1102,14 +1102,12 @@ handle_queued_objects (APP_STATE_T * state) GstMiniObject *object = NULL; gboolean done = FALSE; - if (g_async_queue_length (state->queue) == 0) { - return FALSE; - } - g_mutex_lock (state->queue_lock); if (state->flushing) { g_cond_broadcast (state->cond); done = TRUE; + } else if (g_async_queue_length (state->queue) == 0) { + done = TRUE; } g_mutex_unlock (state->queue_lock); @@ -1180,6 +1178,8 @@ handle_queued_objects (APP_STATE_T * state) state->popped_obj = object; g_cond_broadcast (state->cond); g_mutex_unlock (state->queue_lock); + g_mutex_lock (state->flow_lock); + g_mutex_unlock (state->flow_lock); } return FALSE; @@ -1197,16 +1197,16 @@ queue_object (APP_STATE_T * state, GstMiniObject * obj, gboolean synchronous) goto beach; } + g_mutex_lock (state->queue_lock); g_async_queue_push (state->queue, obj); if (synchronous) { /* Waiting for object to be handled */ - g_mutex_lock (state->queue_lock); do { g_cond_wait (state->cond, state->queue_lock); } while (!state->flushing && state->popped_obj != obj); - g_mutex_unlock (state->queue_lock); } + g_mutex_unlock (state->queue_lock); beach: g_mutex_unlock (state->flow_lock); @@ -1243,7 +1243,7 @@ events_cb (GstPad * pad, GstPadProbeInfo * probe_info, gpointer user_data) flush_stop (state); break; case GST_EVENT_EOS: - queue_object (state, GST_MINI_OBJECT_CAST (gst_event_ref (event)), TRUE); + queue_object (state, GST_MINI_OBJECT_CAST (gst_event_ref (event)), FALSE); break; default: break; @@ -1592,7 +1592,6 @@ eos_cb (GstBus * bus, GstMessage * msg, APP_STATE_T * state) { if (GST_MESSAGE_SRC (msg) == GST_OBJECT (state->pipeline)) { g_print ("End-Of-Stream reached.\n"); - flush_start (state); gst_element_set_state (state->pipeline, GST_STATE_READY); } } -- 2.7.4