Commit f9d55fd3 authored by Youness Alaoui's avatar Youness Alaoui

Make libnice thread-safe

darcs-hash:20080402185805-4f0f6-d575bacdd796be98b42597605baf21b24a331047.gz
parent 84304de6
......@@ -94,6 +94,7 @@ struct _NiceAgent
guint keepalive_timer_id; /**< id of keepalive timer */
guint64 tie_breaker; /**< tie breaker (ICE sect 5.2
"Determining Role" ID-19) */
GMutex * mutex; /* Mutex used for thread-safe lib */
/* XXX: add pointer to internal data struct for ABI-safe extensions */
};
......
This diff is collapsed.
......@@ -322,6 +322,7 @@ static gboolean priv_conn_check_tick_stream (Stream *stream, NiceAgent *agent, G
}
/**
* Timer callback that handles initiating and managing connectivity
* checks (paced by the Ta timer).
......@@ -330,7 +331,7 @@ static gboolean priv_conn_check_tick_stream (Stream *stream, NiceAgent *agent, G
*
* @return will return FALSE when no more pending timers.
*/
static gboolean priv_conn_check_tick (gpointer pointer)
static gboolean priv_conn_check_tick_unlocked (gpointer pointer)
{
CandidateCheckPair *pair = NULL;
NiceAgent *agent = pointer;
......@@ -382,6 +383,18 @@ static gboolean priv_conn_check_tick (gpointer pointer)
return keep_timer_going;
}
static gboolean priv_conn_check_tick (gpointer pointer)
{
NiceAgent *agent = pointer;
gboolean ret;
g_mutex_lock (agent->mutex);
ret = priv_conn_check_tick_unlocked (pointer);
g_mutex_unlock (agent->mutex);
return ret;
}
/**
* Timer callback that handles initiating and managing connectivity
* checks (paced by the Ta timer).
......@@ -396,6 +409,8 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
GSList *i, *j;
int errors = 0;
g_mutex_lock (agent->mutex);
/* case 1: session established and media flowing
* (ref ICE sect 10 "Keepalives" ID-19) */
for (i = agent->streams; i; i = i->next) {
......@@ -441,9 +456,11 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
if (errors) {
g_debug ("%s: stopping keepalive timer", G_STRFUNC);
g_mutex_unlock (agent->mutex);
return FALSE;
}
g_mutex_unlock (agent->mutex);
return TRUE;
}
......@@ -461,7 +478,7 @@ gboolean conn_check_schedule_next (NiceAgent *agent)
if (res == TRUE) {
/* step: call once imediately */
res = priv_conn_check_tick ((gpointer) agent);
res = priv_conn_check_tick_unlocked ((gpointer) agent);
/* step: schedule timer if not running yet */
if (res && agent->conncheck_timer_id == 0)
......
......@@ -459,7 +459,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
*
* @return will return FALSE when no more pending timers.
*/
static gboolean priv_discovery_tick (gpointer pointer)
static gboolean priv_discovery_tick_unlocked (gpointer pointer)
{
CandidateDiscovery *cand;
NiceAgent *agent = pointer;
......@@ -569,6 +569,18 @@ static gboolean priv_discovery_tick (gpointer pointer)
return TRUE;
}
static gboolean priv_discovery_tick (gpointer pointer)
{
NiceAgent *agent = pointer;
gboolean ret;
g_mutex_lock (agent->mutex);
ret = priv_discovery_tick_unlocked (pointer);
g_mutex_unlock (agent->mutex);
return ret;
}
/**
* Initiates the candidate discovery process by starting
* the necessary timers.
......@@ -583,7 +595,7 @@ void discovery_schedule (NiceAgent *agent)
if (agent->discovery_timer_id == 0) {
/* step: run first iteration immediately */
gboolean res = priv_discovery_tick (agent);
gboolean res = priv_discovery_tick_unlocked (agent);
if (res == TRUE) {
agent->discovery_timer_id =
g_timeout_add (agent->timer_ta, priv_discovery_tick, agent);
......
......@@ -53,6 +53,7 @@ main (void)
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
......
......@@ -332,6 +332,7 @@ int main (void)
const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init ();
g_thread_init (NULL);
global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ...
......
......@@ -684,6 +684,7 @@ int main (void)
const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init ();
g_thread_init (NULL);
global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ...
......
......@@ -72,6 +72,7 @@ main (void)
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
agent = nice_agent_new (&factory);
......
......@@ -80,6 +80,7 @@ main (void)
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
/* set up agent */
......
......@@ -53,6 +53,7 @@ main (void)
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
......
......@@ -375,6 +375,7 @@ int main (void)
const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init ();
g_thread_init (NULL);
global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ...
......
......@@ -56,6 +56,7 @@ main (void)
nice_address_init (&addr_local);
nice_address_init (&addr_remote);
g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
......
......@@ -46,6 +46,7 @@ PKG_CHECK_MODULES(OPENSSL, [openssl])
PKG_CHECK_MODULES(GLIB, [dnl
glib-2.0 >= 2.10 dnl
gobject-2.0 >= 2.10 dnl
gthread-2.0 >= 2.10 dnl
])
AC_ARG_WITH(gstreamer,
......
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