[farsight2/master] Don't keep mutex while traversing list

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:26:18 PST 2008


---
 transmitters/nice/fs-nice-transmitter.c |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/transmitters/nice/fs-nice-transmitter.c b/transmitters/nice/fs-nice-transmitter.c
index 4eca537..9a7dae1 100644
--- a/transmitters/nice/fs-nice-transmitter.c
+++ b/transmitters/nice/fs-nice-transmitter.c
@@ -540,16 +540,42 @@ agent_component_state_changed (NiceAgent *agent, guint stream_id,
   g_object_unref (st);
 }
 
+/*
+ * The list traversal in this function should be thread safe as
+ * long as the list is not re-ordered
+ *
+ */
 
 static void
 agent_candidate_gathering_done (NiceAgent *agent, gpointer user_data)
 {
   FsNiceTransmitter *self = FS_NICE_TRANSMITTER (user_data);
+  FsNiceStreamTransmitter *stream = NULL;
+  GList *item;
 
   FS_NICE_TRANSMITTER_LOCK (self);
-  g_list_foreach (self->priv->streams,
-      (GFunc) fs_nice_stream_transmitter_gathering_done, NULL);
+  item = g_list_first (self->priv->streams);
+  if (item)
+    stream = g_object_ref (item->data);
   FS_NICE_TRANSMITTER_UNLOCK (self);
+
+  while (stream)
+  {
+    FsNiceStreamTransmitter *next_stream = NULL;
+
+    fs_nice_stream_transmitter_gathering_done (stream);
+
+    FS_NICE_TRANSMITTER_LOCK (self);
+    item = g_list_find (self->priv->streams, stream);
+    if (item)
+      item = item->next;
+    if (item)
+      next_stream = g_object_ref (item->data);
+    FS_NICE_TRANSMITTER_UNLOCK (self);
+
+    g_object_unref (stream);
+    stream = next_stream;
+  }
 }
 
 static void
-- 
1.5.6.5




More information about the farsight-commits mailing list