From 29aabc223e25a7fe13da5f5c13ef1c1bf107a54c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 20 Dec 2012 18:48:21 +0100 Subject: [PATCH] omxrecmutex: Fix another race condition when two threads are trying to lock for recursion at the same time --- omx/gstomxrecmutex.c | 6 ++++++ omx/gstomxrecmutex.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/omx/gstomxrecmutex.c b/omx/gstomxrecmutex.c index a4e81a8..c12b3aa 100644 --- a/omx/gstomxrecmutex.c +++ b/omx/gstomxrecmutex.c @@ -29,6 +29,7 @@ gst_omx_rec_mutex_init (GstOMXRecMutex * mutex) { g_mutex_init (&mutex->lock); g_mutex_init (&mutex->recursion_lock); + g_cond_init (&mutex->recursion_wait_cond); g_atomic_int_set (&mutex->recursion_allowed, FALSE); g_atomic_int_set (&mutex->recursion_pending, FALSE); } @@ -58,6 +59,10 @@ gst_omx_rec_mutex_lock_for_recursion (GstOMXRecMutex * mutex) gboolean exchanged; g_mutex_lock (&mutex->recursion_lock); + + while (g_atomic_int_get (&mutex->recursion_allowed)) + g_cond_wait (&mutex->recursion_wait_cond, &mutex->recursion_lock); + g_mutex_lock (&mutex->lock); exchanged = g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE, @@ -75,6 +80,7 @@ gst_omx_rec_mutex_unlock_for_recursion (GstOMXRecMutex * mutex) FALSE); g_assert (exchanged); g_mutex_unlock (&mutex->lock); + g_cond_broadcast (&mutex->recursion_wait_cond); g_mutex_unlock (&mutex->recursion_lock); } diff --git a/omx/gstomxrecmutex.h b/omx/gstomxrecmutex.h index 2621239..4645302 100644 --- a/omx/gstomxrecmutex.h +++ b/omx/gstomxrecmutex.h @@ -97,6 +97,8 @@ 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