mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-01 21:18:52 +00:00
omxrecmutex: Fix yet another race condition that resulted in deadlocks
This commit is contained in:
parent
e026926951
commit
500410226f
2 changed files with 6 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue