mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-06 15:38:50 +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->lock);
|
||||||
g_mutex_init (&mutex->recursion_lock);
|
g_mutex_init (&mutex->recursion_lock);
|
||||||
g_atomic_int_set (&mutex->recursion_allowed, FALSE);
|
g_atomic_int_set (&mutex->recursion_allowed, FALSE);
|
||||||
|
g_atomic_int_set (&mutex->recursion_pending, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -56,6 +57,7 @@ gst_omx_rec_mutex_lock_for_recursion (GstOMXRecMutex * mutex)
|
||||||
{
|
{
|
||||||
gboolean exchanged;
|
gboolean exchanged;
|
||||||
|
|
||||||
|
g_mutex_lock (&mutex->recursion_lock);
|
||||||
g_mutex_lock (&mutex->lock);
|
g_mutex_lock (&mutex->lock);
|
||||||
exchanged =
|
exchanged =
|
||||||
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE,
|
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,
|
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE,
|
||||||
FALSE);
|
FALSE);
|
||||||
g_assert (exchanged);
|
g_assert (exchanged);
|
||||||
g_cond_broadcast (&mutex->recursion_wait_cond);
|
|
||||||
g_mutex_unlock (&mutex->lock);
|
g_mutex_unlock (&mutex->lock);
|
||||||
|
g_mutex_unlock (&mutex->recursion_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* must be called with mutex->lock taken */
|
/* must be called with mutex->lock taken */
|
||||||
|
@ -82,7 +84,6 @@ gst_omx_rec_mutex_begin_recursion (GstOMXRecMutex * mutex)
|
||||||
{
|
{
|
||||||
gboolean exchanged;
|
gboolean exchanged;
|
||||||
|
|
||||||
g_mutex_lock (&mutex->recursion_lock);
|
|
||||||
exchanged =
|
exchanged =
|
||||||
g_atomic_int_compare_and_exchange (&mutex->recursion_allowed, FALSE,
|
g_atomic_int_compare_and_exchange (&mutex->recursion_allowed, FALSE,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
@ -91,7 +92,6 @@ gst_omx_rec_mutex_begin_recursion (GstOMXRecMutex * mutex)
|
||||||
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE,
|
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, TRUE,
|
||||||
FALSE);
|
FALSE);
|
||||||
g_assert (exchanged);
|
g_assert (exchanged);
|
||||||
g_cond_broadcast (&mutex->recursion_wait_cond);
|
|
||||||
g_mutex_unlock (&mutex->recursion_lock);
|
g_mutex_unlock (&mutex->recursion_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,24 +110,17 @@ gst_omx_rec_mutex_end_recursion (GstOMXRecMutex * mutex)
|
||||||
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE,
|
g_atomic_int_compare_and_exchange (&mutex->recursion_pending, FALSE,
|
||||||
TRUE);
|
TRUE);
|
||||||
g_assert (exchanged);
|
g_assert (exchanged);
|
||||||
g_mutex_unlock (&mutex->recursion_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_omx_rec_mutex_recursive_lock (GstOMXRecMutex * mutex)
|
gst_omx_rec_mutex_recursive_lock (GstOMXRecMutex * mutex)
|
||||||
{
|
{
|
||||||
g_mutex_lock (&mutex->recursion_lock);
|
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)) {
|
if (!g_atomic_int_get (&mutex->recursion_allowed)) {
|
||||||
/* no recursion allowed, lock the proper mutex */
|
/* no recursion allowed, lock the proper mutex */
|
||||||
g_mutex_lock (&mutex->lock);
|
g_mutex_lock (&mutex->lock);
|
||||||
g_mutex_unlock (&mutex->recursion_lock);
|
g_mutex_unlock (&mutex->recursion_lock);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -97,7 +97,6 @@ struct _GstOMXRecMutex {
|
||||||
* will be allowed soon
|
* will be allowed soon
|
||||||
*/
|
*/
|
||||||
volatile gint recursion_pending;
|
volatile gint recursion_pending;
|
||||||
GCond recursion_wait_cond;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void gst_omx_rec_mutex_init (GstOMXRecMutex * mutex);
|
void gst_omx_rec_mutex_init (GstOMXRecMutex * mutex);
|
||||||
|
|
Loading…
Reference in a new issue