[Pkg-telepathy-commits] [libnice] 133/265: agent: Remove weak pointers, they aren't thread safe anyway

Simon McVittie smcv at debian.org
Wed May 14 12:05:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository libnice.

commit faa90ddafd4a43533be13b2b2ca646c9edfa12c2
Author: Olivier Crête <olivier.crete at collabora.com>
Date:   Fri Jan 31 01:06:08 2014 -0500

    agent: Remove weak pointers, they aren't thread safe anyway
    
    And we get close to 10% perf boost
---
 agent/agent.c     | 70 +++++++++++++++++++++++++++++++------------------------
 agent/component.c | 11 +++++----
 2 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/agent/agent.c b/agent/agent.c
index c04590e..4662113 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1171,14 +1171,16 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
   NiceAgent *agent = component->agent;
   Stream *stream = component->stream;
   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,
       stream->id, component->id);
 
   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);
 
   /* 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)
 
       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!");
-        break;
+        goto out;
       }
 
       has_io_callback = component_has_io_callback (component);
@@ -1257,14 +1264,13 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
     nice_debug ("%s: no data read", G_STRFUNC);
   }
 
-  if (agent) {
+  if (stream && component)
     adjust_tcp_clock (agent, stream, component);
-    g_object_remove_weak_pointer (G_OBJECT (agent), (gpointer *)&agent);
-  } else {
-    nice_debug ("Not calling adjust_tcp_clock.. agent got destroyed!");
-  }
-  if (sock)
-    g_object_remove_weak_pointer (G_OBJECT (sock), (gpointer *)&sock);
+
+out:
+
+  g_object_unref (agent);
+
 }
 
 static void
@@ -1473,6 +1479,8 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream,
     Component *component)
 {
   GOutputVector *vec;
+  guint stream_id = stream->id;
+  guint component_id = component->id;
 
   if (component->selected_pair.local == NULL || component->tcp == NULL)
     return;
@@ -1483,20 +1491,24 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream,
   while ((vec = g_queue_peek_head (&component->queued_tcp_packets)) != NULL) {
     gboolean retval;
 
-    g_object_add_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
-
     nice_debug ("%s: Sending %" G_GSIZE_FORMAT " bytes.", G_STRFUNC, vec->size);
     retval =
         pseudo_tcp_socket_notify_packet (component->tcp, vec->buffer,
             vec->size);
 
-    if (agent != NULL) {
-      adjust_tcp_clock (agent, stream, component);
-      g_object_remove_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
-    } else {
-      nice_debug ("%s: Agent %p was destroyed in "
-          "pseudo_tcp_socket_notify_packet().", G_STRFUNC, agent);
+    if (!agent_find_component (agent, stream_id, component_id,
+            &stream, &component)) {
+      nice_debug ("Stream or Component disappeared during "
+          "pseudo_tcp_socket_notify_packet()");
+      return;
     }
+    if (!component->tcp) {
+      nice_debug ("PseudoTCP socket got destroyed in"
+          " pseudo_tcp_socket_notify_packet()!");
+      return;
+    }
+
+    adjust_tcp_clock (agent, stream, component);
 
     if (!retval) {
       /* Failed to send; try again later. */
@@ -2713,18 +2725,12 @@ agent_recv_message_unlocked (
     }
 
     /* 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,
         G_STRFUNC, message->length);
     pseudo_tcp_socket_notify_message (component->tcp, message);
 
-    if (agent) {
-      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!!");
-    }
+    adjust_tcp_clock (agent, stream, component);
 
     /* Success! Handled out-of-band. */
     retval = RECV_OOB;
@@ -3544,10 +3550,6 @@ component_io_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
 
   agent_lock ();
 
-  component = socket_source->component;
-  agent = component->agent;
-  stream = component->stream;
-
   if (g_source_is_destroyed (g_main_current_source ())) {
     /* Silently return FALSE. */
     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)
     goto done;
   }
 
+  component = socket_source->component;
+  agent = component->agent;
+  stream = component->stream;
+
+  g_object_ref (agent);
+
   has_io_callback = component_has_io_callback (component);
 
   /* 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)
   }
 
 done:
+  g_object_unref (agent);
+
   agent_unlock ();
 
   return !remove_source;
diff --git a/agent/component.c b/agent/component.c
index a2044f0..296f353 100644
--- a/agent/component.c
+++ b/agent/component.c
@@ -652,7 +652,8 @@ emit_io_callback_cb (gpointer user_data)
   NiceAgent *agent;
 
   agent = component->agent;
-  g_object_add_weak_pointer (G_OBJECT (agent), (gpointer *) &agent);
+
+  g_object_ref (agent);
 
   stream_id = component->stream->id;
   component_id = component->id;
@@ -690,11 +691,10 @@ emit_io_callback_cb (gpointer user_data)
         io_user_data);
 
     /* Check for the user destroying things underneath our feet. */
-    if (agent == NULL ||
-        !agent_find_component (agent, stream_id, component_id,
+    if (!agent_find_component (agent, stream_id, component_id,
             NULL, &component)) {
       nice_debug ("%s: Agent or component destroyed.", G_STRFUNC);
-      return G_SOURCE_REMOVE;
+      goto done;
     }
 
     g_queue_pop_head (&component->pending_io_messages);
@@ -706,7 +706,8 @@ emit_io_callback_cb (gpointer user_data)
   component->io_callback_id = 0;
   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;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/libnice.git



More information about the Pkg-telepathy-commits mailing list