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 ...@@ -94,6 +94,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 */
/* 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.
...@@ -322,6 +322,7 @@ static gboolean priv_conn_check_tick_stream (Stream *stream, NiceAgent *agent, G ...@@ -322,6 +322,7 @@ static gboolean priv_conn_check_tick_stream (Stream *stream, NiceAgent *agent, G
} }
/** /**
* Timer callback that handles initiating and managing connectivity * Timer callback that handles initiating and managing connectivity
* checks (paced by the Ta timer). * checks (paced by the Ta timer).
...@@ -330,7 +331,7 @@ static gboolean priv_conn_check_tick_stream (Stream *stream, NiceAgent *agent, G ...@@ -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. * @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; CandidateCheckPair *pair = NULL;
NiceAgent *agent = pointer; NiceAgent *agent = pointer;
...@@ -382,6 +383,18 @@ static gboolean priv_conn_check_tick (gpointer pointer) ...@@ -382,6 +383,18 @@ static gboolean priv_conn_check_tick (gpointer pointer)
return keep_timer_going; 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 * Timer callback that handles initiating and managing connectivity
* checks (paced by the Ta timer). * checks (paced by the Ta timer).
...@@ -396,6 +409,8 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer) ...@@ -396,6 +409,8 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
GSList *i, *j; GSList *i, *j;
int errors = 0; int errors = 0;
g_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) */
for (i = agent->streams; i; i = i->next) { for (i = agent->streams; i; i = i->next) {
...@@ -441,9 +456,11 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer) ...@@ -441,9 +456,11 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
if (errors) { if (errors) {
g_debug ("%s: stopping keepalive timer", G_STRFUNC); g_debug ("%s: stopping keepalive timer", G_STRFUNC);
g_mutex_unlock (agent->mutex);
return FALSE; return FALSE;
} }
g_mutex_unlock (agent->mutex);
return TRUE; return TRUE;
} }
...@@ -461,7 +478,7 @@ gboolean conn_check_schedule_next (NiceAgent *agent) ...@@ -461,7 +478,7 @@ gboolean conn_check_schedule_next (NiceAgent *agent)
if (res == TRUE) { if (res == TRUE) {
/* step: call once imediately */ /* 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 */ /* step: schedule timer if not running yet */
if (res && agent->conncheck_timer_id == 0) if (res && agent->conncheck_timer_id == 0)
......
...@@ -459,7 +459,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -459,7 +459,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
* *
* @return will return FALSE when no more pending timers. * @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; CandidateDiscovery *cand;
NiceAgent *agent = pointer; NiceAgent *agent = pointer;
...@@ -569,6 +569,18 @@ static gboolean priv_discovery_tick (gpointer pointer) ...@@ -569,6 +569,18 @@ static gboolean priv_discovery_tick (gpointer pointer)
return TRUE; 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 * Initiates the candidate discovery process by starting
* the necessary timers. * the necessary timers.
...@@ -583,7 +595,7 @@ void discovery_schedule (NiceAgent *agent) ...@@ -583,7 +595,7 @@ void discovery_schedule (NiceAgent *agent)
if (agent->discovery_timer_id == 0) { if (agent->discovery_timer_id == 0) {
/* step: run first iteration immediately */ /* step: run first iteration immediately */
gboolean res = priv_discovery_tick (agent); gboolean res = priv_discovery_tick_unlocked (agent);
if (res == TRUE) { if (res == TRUE) {
agent->discovery_timer_id = agent->discovery_timer_id =
g_timeout_add (agent->timer_ta, priv_discovery_tick, agent); g_timeout_add (agent->timer_ta, priv_discovery_tick, agent);
......
...@@ -53,6 +53,7 @@ main (void) ...@@ -53,6 +53,7 @@ main (void)
nice_address_init (&addr); nice_address_init (&addr);
g_type_init (); g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
......
...@@ -332,6 +332,7 @@ int main (void) ...@@ -332,6 +332,7 @@ int main (void)
const char *stun_server = NULL, *stun_server_port = NULL; const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init (); g_type_init ();
g_thread_init (NULL);
global_mainloop = g_main_loop_new (NULL, FALSE); global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ... /* Note: impl limits ...
......
...@@ -684,6 +684,7 @@ int main (void) ...@@ -684,6 +684,7 @@ int main (void)
const char *stun_server = NULL, *stun_server_port = NULL; const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init (); g_type_init ();
g_thread_init (NULL);
global_mainloop = g_main_loop_new (NULL, FALSE); global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ... /* Note: impl limits ...
......
...@@ -72,6 +72,7 @@ main (void) ...@@ -72,6 +72,7 @@ main (void)
nice_address_init (&addr); nice_address_init (&addr);
g_type_init (); g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
agent = nice_agent_new (&factory); agent = nice_agent_new (&factory);
......
...@@ -80,6 +80,7 @@ main (void) ...@@ -80,6 +80,7 @@ main (void)
nice_address_init (&addr); nice_address_init (&addr);
g_type_init (); g_type_init ();
g_thread_init (NULL);
/* set up agent */ /* set up agent */
......
...@@ -53,6 +53,7 @@ main (void) ...@@ -53,6 +53,7 @@ main (void)
nice_address_init (&addr); nice_address_init (&addr);
g_type_init (); g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
......
...@@ -375,6 +375,7 @@ int main (void) ...@@ -375,6 +375,7 @@ int main (void)
const char *stun_server = NULL, *stun_server_port = NULL; const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init (); g_type_init ();
g_thread_init (NULL);
global_mainloop = g_main_loop_new (NULL, FALSE); global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ... /* Note: impl limits ...
......
...@@ -56,6 +56,7 @@ main (void) ...@@ -56,6 +56,7 @@ main (void)
nice_address_init (&addr_local); nice_address_init (&addr_local);
nice_address_init (&addr_remote); nice_address_init (&addr_remote);
g_type_init (); g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
......
...@@ -46,6 +46,7 @@ PKG_CHECK_MODULES(OPENSSL, [openssl]) ...@@ -46,6 +46,7 @@ PKG_CHECK_MODULES(OPENSSL, [openssl])
PKG_CHECK_MODULES(GLIB, [dnl PKG_CHECK_MODULES(GLIB, [dnl
glib-2.0 >= 2.10 dnl glib-2.0 >= 2.10 dnl
gobject-2.0 >= 2.10 dnl gobject-2.0 >= 2.10 dnl
gthread-2.0 >= 2.10 dnl
]) ])
AC_ARG_WITH(gstreamer, 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