Commit 56e04b56 authored by Philip Withnall's avatar Philip Withnall Committed by Olivier Crête

agent: Split component_free() into component_[close|free]()

Closing a component and freeing it are slightly conceptually different.
As it happens, freeing it can result in the disposal of the component's
NiceIOStream, which requires the agent lock to be released — but closing
the rest of the Component requires the agent lock to be held. Splitting
the function up simplifies locking handling in other parts of the code
(see next commit).
parent c61f3780
......@@ -2889,6 +2889,7 @@ nice_agent_remove_stream (
/* Remove the stream and signal its removal. */
agent->streams = g_slist_remove (agent->streams, stream);
stream_close (stream);
stream_free (stream);
if (!agent->streams)
......
......@@ -205,8 +205,10 @@ component_clear_selected_pair (Component *component)
memset (&component->selected_pair, 0, sizeof(CandidatePair));
}
/* Must be called with the agent lock held as it touches internal Component
* state. */
void
component_free (Component *cmp)
component_close (Component *cmp)
{
GSList *i;
IOCallbackData *data;
......@@ -257,7 +259,6 @@ component_free (Component *cmp)
}
if (cmp->tcp) {
pseudo_tcp_socket_close (cmp->tcp, TRUE);
g_clear_object(&cmp->tcp);
}
while ((data = g_queue_pop_head (&cmp->pending_io_messages)) != NULL)
......@@ -266,24 +267,30 @@ component_free (Component *cmp)
component_deschedule_io_callback (cmp);
g_cancellable_cancel (cmp->stop_cancellable);
g_clear_object (&cmp->stop_cancellable);
if (cmp->ctx != NULL) {
g_main_context_unref (cmp->ctx);
cmp->ctx = NULL;
}
g_main_context_unref (cmp->own_ctx);
while ((vec = g_queue_pop_head (&cmp->queued_tcp_packets)) != NULL) {
g_free ((gpointer) vec->buffer);
g_slice_free (GOutputVector, vec);
}
}
/* Must be called with the agent lock released as it could dispose of
* NiceIOStreams. */
void
component_free (Component *cmp)
{
g_clear_object (&cmp->tcp);
g_clear_object (&cmp->stop_cancellable);
g_clear_object (&cmp->iostream);
g_mutex_clear (&cmp->io_mutex);
if (cmp->ctx != NULL) {
g_main_context_unref (cmp->ctx);
cmp->ctx = NULL;
}
g_main_context_unref (cmp->own_ctx);
g_slice_free (Component, cmp);
}
......
......@@ -208,6 +208,9 @@ struct _Component
Component *
component_new (guint component_id, NiceAgent *agent, Stream *stream);
void
component_close (Component *cmp);
void
component_free (Component *cmp);
......
......@@ -66,6 +66,17 @@ stream_new (guint n_components, NiceAgent *agent)
return stream;
}
void
stream_close (Stream *stream)
{
GSList *i;
for (i = stream->components; i; i = i->next) {
Component *component = i->data;
component_close (component);
}
}
void
stream_free (Stream *stream)
{
......
......@@ -80,6 +80,9 @@ struct _Stream
Stream *
stream_new (guint n_components, NiceAgent *agent);
void
stream_close (Stream *stream);
void
stream_free (Stream *stream);
......
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