From 500410226f62928638b5ffb4a8ed292fafa46c95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 20 Dec 2012 18:16:43 +0100 Subject: [PATCH] omxrecmutex: Fix yet another race condition that resulted in deadlocks --- omx/gstomxrecmutex.c | 19 ++++++------------- omx/gstomxrecmutex.h | 1 - 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/omx/gstomxrecmutex.c b/omx/gstomxrecmutex.c index 6972bc2..a4e81a8 100644 --- a/omx/gstomxrecmutex.c +++ b/omx/gstomxrecmutex.c @@ -30,6 +30,7 @@ gst_omx_rec_mutex_init (GstOMXRecMutex * mutex) g_mutex_init (&mutex->lock); g_mutex_init (&mutex->recursion_lock); g_atomic_int_set (&mutex->recursion_allowed, FALSE); + g_atomic_int_set (&mutex->recursion_pending, FALSE); } void @@ -56,6 +57,7 @@ gst_omx_rec_mutex_lock_for_recursion (GstOMXRecMutex * mutex) { gboolean exchanged; + g_mutex_lock (&mutex->recursion_lock); g_mutex_lock (&mutex->lock); exchanged = g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE, @@ -72,8 +74,8 @@ gst_omx_rec_mutex_unlock_for_recursion (GstOMXRecMutex * mutex) g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE, FALSE); g_assert (exchanged); - g_cond_broadcast (&mutex->recursion_wait_cond); g_mutex_unlock (&mutex->lock); + g_mutex_unlock (&mutex->recursion_lock); } /* must be called with mutex->lock taken */ @@ -82,7 +84,6 @@ gst_omx_rec_mutex_begin_recursion (GstOMXRecMutex * mutex) { gboolean exchanged; - g_mutex_lock (&mutex->recursion_lock); exchanged = g_atomic_int_compare_and_exchange (&mutex->recursion_allowed, FALSE, TRUE); @@ -91,7 +92,6 @@ gst_omx_rec_mutex_begin_recursion (GstOMXRecMutex * mutex) g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE, FALSE); g_assert (exchanged); - g_cond_broadcast (&mutex->recursion_wait_cond); g_mutex_unlock (&mutex->recursion_lock); } @@ -110,7 +110,6 @@ gst_omx_rec_mutex_end_recursion (GstOMXRecMutex * mutex) g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE, TRUE); g_assert (exchanged); - g_mutex_unlock (&mutex->recursion_lock); } void @@ -118,15 +117,9 @@ gst_omx_rec_mutex_recursive_lock (GstOMXRecMutex * mutex) { g_mutex_lock (&mutex->recursion_lock); if (!g_atomic_int_get (&mutex->recursion_allowed)) { - /* If recursion is pending wait until it happened */ - while (g_atomic_int_get (&mutex->recursion_pending)) - g_cond_wait (&mutex->recursion_wait_cond, &mutex->recursion_lock); - - if (!g_atomic_int_get (&mutex->recursion_allowed)) { - /* no recursion allowed, lock the proper mutex */ - g_mutex_lock (&mutex->lock); - g_mutex_unlock (&mutex->recursion_lock); - } + /* no recursion allowed, lock the proper mutex */ + g_mutex_lock (&mutex->lock); + g_mutex_unlock (&mutex->recursion_lock); } } diff --git a/omx/gstomxrecmutex.h b/omx/gstomxrecmutex.h index 92aec39..2621239 100644 --- a/omx/gstomxrecmutex.h +++ b/omx/gstomxrecmutex.h @@ -97,7 +97,6 @@ struct _GstOMXRecMutex { * will be allowed soon */ volatile gint recursion_pending; - GCond recursion_wait_cond; }; void gst_omx_rec_mutex_init (GstOMXRecMutex * mutex); -- 2.7.4