Commit 41961275 authored by Youness Alaoui's avatar Youness Alaoui

Do not unlock the mutex when emitting the signal because it might unlock...

Do not unlock the mutex when emitting the signal because it might unlock another thread which could cause a race condition.
To avoid a deadlock when a signal callback calls an API function that does a g_mutex_lock while the lock is already taken. Change the mutex into a recursive mutex
parent f07a470f
...@@ -91,7 +91,7 @@ struct _NiceAgent ...@@ -91,7 +91,7 @@ struct _NiceAgent
guint keepalive_timer_id; /**< id of keepalive timer */ guint keepalive_timer_id; /**< id of keepalive timer */
guint64 tie_breaker; /**< tie breaker (ICE sect 5.2 guint64 tie_breaker; /**< tie breaker (ICE sect 5.2
"Determining Role" ID-19) */ "Determining Role" ID-19) */
GMutex * mutex; /* Mutex used for thread-safe lib */ GStaticRecMutex mutex; /* Mutex used for thread-safe lib */
NiceCompatibility compatibility; /* property: Compatibility mode */ NiceCompatibility compatibility; /* property: Compatibility mode */
/* XXX: add pointer to internal data struct for ABI-safe extensions */ /* XXX: add pointer to internal data struct for ABI-safe extensions */
}; };
......
This diff is collapsed.
...@@ -389,9 +389,9 @@ static gboolean priv_conn_check_tick (gpointer pointer) ...@@ -389,9 +389,9 @@ static gboolean priv_conn_check_tick (gpointer pointer)
NiceAgent *agent = pointer; NiceAgent *agent = pointer;
gboolean ret; gboolean ret;
g_mutex_lock (agent->mutex); g_static_rec_mutex_lock (&agent->mutex);
ret = priv_conn_check_tick_unlocked (pointer); ret = priv_conn_check_tick_unlocked (pointer);
g_mutex_unlock (agent->mutex); g_static_rec_mutex_unlock (&agent->mutex);
return ret; return ret;
} }
...@@ -411,7 +411,7 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer) ...@@ -411,7 +411,7 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
int errors = 0; int errors = 0;
gboolean ret = FALSE; gboolean ret = FALSE;
g_mutex_lock (agent->mutex); g_static_rec_mutex_lock (&agent->mutex);
/* case 1: session established and media flowing /* case 1: session established and media flowing
* (ref ICE sect 10 "Keepalives" ID-19) */ * (ref ICE sect 10 "Keepalives" ID-19) */
...@@ -464,7 +464,7 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer) ...@@ -464,7 +464,7 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
ret = TRUE; ret = TRUE;
done: done:
g_mutex_unlock (agent->mutex); g_static_rec_mutex_unlock (&agent->mutex);
return ret; return ret;
} }
......
...@@ -576,9 +576,9 @@ static gboolean priv_discovery_tick (gpointer pointer) ...@@ -576,9 +576,9 @@ static gboolean priv_discovery_tick (gpointer pointer)
NiceAgent *agent = pointer; NiceAgent *agent = pointer;
gboolean ret; gboolean ret;
g_mutex_lock (agent->mutex); g_static_rec_mutex_lock (&agent->mutex);
ret = priv_discovery_tick_unlocked (pointer); ret = priv_discovery_tick_unlocked (pointer);
g_mutex_unlock (agent->mutex); g_static_rec_mutex_unlock (&agent->mutex);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment