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

agent: Remove weak pointers, they aren't thread safe anyway

And we get close to 10% perf boost
parent 011e3c29
...@@ -1171,14 +1171,16 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1171,14 +1171,16 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
NiceAgent *agent = component->agent; NiceAgent *agent = component->agent;
Stream *stream = component->stream; Stream *stream = component->stream;
gboolean has_io_callback; gboolean has_io_callback;
guint stream_id = stream->id;
guint component_id = component->id;
g_object_ref (agent);
nice_debug ("Agent %p: s%d:%d pseudo Tcp socket readable", agent, nice_debug ("Agent %p: s%d:%d pseudo Tcp socket readable", agent,
stream->id, component->id); stream->id, component->id);
component->tcp_readable = TRUE; component->tcp_readable = TRUE;
g_object_add_weak_pointer (G_OBJECT (sock), (gpointer *)&sock);
g_object_add_weak_pointer (G_OBJECT (agent), (gpointer *)&agent);
has_io_callback = component_has_io_callback (component); has_io_callback = component_has_io_callback (component);
/* Only dequeue pseudo-TCP data if we can reliably inform the client. The /* Only dequeue pseudo-TCP data if we can reliably inform the client. The
...@@ -1224,9 +1226,14 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1224,9 +1226,14 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
component_emit_io_callback (component, buf, len); component_emit_io_callback (component, buf, len);
if (sock == NULL) { if (!agent_find_component (agent, stream_id, component_id,
&stream, &component)) {
nice_debug ("Stream or Component disappeared during the callback");
goto out;
}
if (!component->tcp) {
nice_debug ("PseudoTCP socket got destroyed in readable callback!"); nice_debug ("PseudoTCP socket got destroyed in readable callback!");
break; goto out;
} }
has_io_callback = component_has_io_callback (component); has_io_callback = component_has_io_callback (component);
...@@ -1257,14 +1264,13 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1257,14 +1264,13 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
nice_debug ("%s: no data read", G_STRFUNC); nice_debug ("%s: no data read", G_STRFUNC);
} }
if (agent) { if (stream && component)
adjust_tcp_clock (agent, stream, component); adjust_tcp_clock (agent, stream, component);
g_object_remove_weak_pointer (G_OBJECT (agent), (gpointer *)&agent);
} else { out:
nice_debug ("Not calling adjust_tcp_clock.. agent got destroyed!");
} g_object_unref (agent);
if (sock)
g_object_remove_weak_pointer (G_OBJECT (sock), (gpointer *)&sock);
} }
static void static void
...@@ -1473,6 +1479,8 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream, ...@@ -1473,6 +1479,8 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream,
Component *component) Component *component)
{ {
GOutputVector *vec; GOutputVector *vec;
guint stream_id = stream->id;
guint component_id = component->id;
if (component->selected_pair.local == NULL || component->tcp == NULL) if (component->selected_pair.local == NULL || component->tcp == NULL)
return; return;
...@@ -1483,20 +1491,24 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream, ...@@ -1483,20 +1491,24 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream,
while ((vec = g_queue_peek_head (&component->queued_tcp_packets)) != NULL) { while ((vec = g_queue_peek_head (&component->queued_tcp_packets)) != NULL) {
gboolean retval; gboolean retval;
g_object_add_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
nice_debug ("%s: Sending %" G_GSIZE_FORMAT " bytes.", G_STRFUNC, vec->size); nice_debug ("%s: Sending %" G_GSIZE_FORMAT " bytes.", G_STRFUNC, vec->size);
retval = retval =
pseudo_tcp_socket_notify_packet (component->tcp, vec->buffer, pseudo_tcp_socket_notify_packet (component->tcp, vec->buffer,
vec->size); vec->size);
if (agent != NULL) { if (!agent_find_component (agent, stream_id, component_id,
adjust_tcp_clock (agent, stream, component); &stream, &component)) {
g_object_remove_weak_pointer (G_OBJECT (agent), (gpointer *) &agent); nice_debug ("Stream or Component disappeared during "
} else { "pseudo_tcp_socket_notify_packet()");
nice_debug ("%s: Agent %p was destroyed in " return;
"pseudo_tcp_socket_notify_packet().", G_STRFUNC, agent);
} }
if (!component->tcp) {
nice_debug ("PseudoTCP socket got destroyed in"
" pseudo_tcp_socket_notify_packet()!");
return;
}
adjust_tcp_clock (agent, stream, component);
if (!retval) { if (!retval) {
/* Failed to send; try again later. */ /* Failed to send; try again later. */
...@@ -2713,18 +2725,12 @@ agent_recv_message_unlocked ( ...@@ -2713,18 +2725,12 @@ agent_recv_message_unlocked (
} }
/* Received data on a reliable connection. */ /* Received data on a reliable connection. */
g_object_add_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
nice_debug ("%s: notifying pseudo-TCP of packet, length %" G_GSIZE_FORMAT, nice_debug ("%s: notifying pseudo-TCP of packet, length %" G_GSIZE_FORMAT,
G_STRFUNC, message->length); G_STRFUNC, message->length);
pseudo_tcp_socket_notify_message (component->tcp, message); pseudo_tcp_socket_notify_message (component->tcp, message);
if (agent) { adjust_tcp_clock (agent, stream, component);
adjust_tcp_clock (agent, stream, component);
g_object_remove_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
} else {
nice_debug ("Our agent got destroyed in notify_packet!!");
}
/* Success! Handled out-of-band. */ /* Success! Handled out-of-band. */
retval = RECV_OOB; retval = RECV_OOB;
...@@ -3544,10 +3550,6 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data) ...@@ -3544,10 +3550,6 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
agent_lock (); agent_lock ();
component = socket_source->component;
agent = component->agent;
stream = component->stream;
if (g_source_is_destroyed (g_main_current_source ())) { if (g_source_is_destroyed (g_main_current_source ())) {
/* Silently return FALSE. */ /* Silently return FALSE. */
nice_debug ("%s: source %p destroyed", G_STRFUNC, g_main_current_source ()); nice_debug ("%s: source %p destroyed", G_STRFUNC, g_main_current_source ());
...@@ -3555,6 +3557,12 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data) ...@@ -3555,6 +3557,12 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
goto done; goto done;
} }
component = socket_source->component;
agent = component->agent;
stream = component->stream;
g_object_ref (agent);
has_io_callback = component_has_io_callback (component); has_io_callback = component_has_io_callback (component);
/* Choose which receive buffer to use. If we’re reading for /* Choose which receive buffer to use. If we’re reading for
...@@ -3695,6 +3703,8 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data) ...@@ -3695,6 +3703,8 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
} }
done: done:
g_object_unref (agent);
agent_unlock (); agent_unlock ();
return !remove_source; return !remove_source;
......
...@@ -652,7 +652,8 @@ emit_io_callback_cb (gpointer user_data) ...@@ -652,7 +652,8 @@ emit_io_callback_cb (gpointer user_data)
NiceAgent *agent; NiceAgent *agent;
agent = component->agent; agent = component->agent;
g_object_add_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
g_object_ref (agent);
stream_id = component->stream->id; stream_id = component->stream->id;
component_id = component->id; component_id = component->id;
...@@ -690,11 +691,10 @@ emit_io_callback_cb (gpointer user_data) ...@@ -690,11 +691,10 @@ emit_io_callback_cb (gpointer user_data)
io_user_data); io_user_data);
/* Check for the user destroying things underneath our feet. */ /* Check for the user destroying things underneath our feet. */
if (agent == NULL || if (!agent_find_component (agent, stream_id, component_id,
!agent_find_component (agent, stream_id, component_id,
NULL, &component)) { NULL, &component)) {
nice_debug ("%s: Agent or component destroyed.", G_STRFUNC); nice_debug ("%s: Agent or component destroyed.", G_STRFUNC);
return G_SOURCE_REMOVE; goto done;
} }
g_queue_pop_head (&component->pending_io_messages); g_queue_pop_head (&component->pending_io_messages);
...@@ -706,7 +706,8 @@ emit_io_callback_cb (gpointer user_data) ...@@ -706,7 +706,8 @@ emit_io_callback_cb (gpointer user_data)
component->io_callback_id = 0; component->io_callback_id = 0;
g_mutex_unlock (&component->io_mutex); g_mutex_unlock (&component->io_mutex);
g_object_remove_weak_pointer (G_OBJECT (agent), (gpointer *) &agent); done:
g_object_unref (agent);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
......
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