Commit ca0f5c6d authored by Olivier Crête's avatar Olivier Crête

agent: Delay signal emission after the lock has been released

This way, there can be no annoying re-entrancy in our code.
parent 0fc36cb2
......@@ -158,6 +158,8 @@ struct _NiceAgent
#endif
gchar *software_attribute; /* SOFTWARE attribute */
gboolean reliable; /* property: reliable */
GQueue pending_signals;
/* XXX: add pointer to internal data struct for ABI-safe extensions */
};
......@@ -176,6 +178,7 @@ void agent_signal_gathering_done (NiceAgent *agent);
void agent_lock (void);
void agent_unlock (void);
void agent_unlock_and_emit (NiceAgent *agent);
void agent_signal_new_selected_pair (
NiceAgent *agent,
......
This diff is collapsed.
......@@ -752,7 +752,7 @@ component_emit_io_callback (Component *component,
* handler. */
if (g_main_context_is_owner (component->ctx)) {
/* Thread owns the main context, so invoke the callback directly. */
agent_unlock ();
agent_unlock_and_emit (agent);
io_callback (agent, stream_id,
component_id, buf_len, (gchar *) buf, io_user_data);
agent_lock ();
......@@ -907,7 +907,7 @@ component_source_prepare (GSource *source, gint *timeout_)
done:
agent_unlock ();
agent_unlock_and_emit (agent);
/* We can’t be sure if the ComponentSource itself needs to be dispatched until
* poll() is called on all the child sources. */
......
......@@ -388,10 +388,9 @@ 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_unlocked (gpointer pointer)
static gboolean priv_conn_check_tick_unlocked (NiceAgent *agent)
{
CandidateCheckPair *pair = NULL;
NiceAgent *agent = pointer;
gboolean keep_timer_going = FALSE;
GSList *i, *j;
GTimeVal now;
......@@ -454,6 +453,7 @@ static gboolean priv_conn_check_tick_unlocked (gpointer pointer)
static gboolean priv_conn_check_tick (gpointer pointer)
{
gboolean ret;
NiceAgent *agent = pointer;
agent_lock();
if (g_source_is_destroyed (g_main_current_source ())) {
......@@ -462,8 +462,9 @@ static gboolean priv_conn_check_tick (gpointer pointer)
agent_unlock ();
return FALSE;
}
ret = priv_conn_check_tick_unlocked (pointer);
agent_unlock();
ret = priv_conn_check_tick_unlocked (agent);
agent_unlock_and_emit (agent);
return ret;
}
......@@ -539,7 +540,7 @@ static gboolean priv_conn_keepalive_retransmissions_tick (gpointer pointer)
}
agent_unlock ();
agent_unlock_and_emit (pair->keepalive.agent);
return FALSE;
}
......@@ -723,7 +724,7 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer)
agent->keepalive_timer_source = NULL;
}
}
agent_unlock();
agent_unlock_and_emit (agent);
return ret;
}
......@@ -782,7 +783,7 @@ static gboolean priv_turn_allocate_refresh_retransmissions_tick (gpointer pointe
}
agent_unlock ();
agent_unlock_and_emit (cand->agent);
return FALSE;
}
......@@ -867,7 +868,7 @@ static gboolean priv_turn_allocate_refresh_tick (gpointer pointer)
}
priv_turn_allocate_refresh_tick_unlocked (cand);
agent_unlock ();
agent_unlock_and_emit (cand->agent);
return FALSE;
}
......@@ -887,7 +888,7 @@ gboolean conn_check_schedule_next (NiceAgent *agent)
nice_debug ("Agent %p : WARN: starting conn checks before local candidate gathering is finished.", agent);
/* step: call once imediately */
res = priv_conn_check_tick_unlocked ((gpointer) agent);
res = priv_conn_check_tick_unlocked (agent);
nice_debug ("Agent %p : priv_conn_check_tick_unlocked returned %d", agent, res);
/* step: schedule timer if not running yet */
......
......@@ -1029,7 +1029,7 @@ static gboolean priv_discovery_tick (gpointer pointer)
agent->discovery_timer_source = NULL;
}
}
agent_unlock();
agent_unlock_and_emit (agent);
return ret;
}
......@@ -1045,7 +1045,7 @@ void discovery_schedule (NiceAgent *agent)
g_assert (agent->discovery_list != NULL);
if (agent->discovery_unsched_items > 0) {
if (agent->discovery_timer_source == NULL) {
/* step: run first iteration immediately */
gboolean res = priv_discovery_tick_unlocked (agent);
......
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