[xiph-commits] r10017 - icecast/trunk/icecast/src

msmith at svn.xiph.org msmith at svn.xiph.org
Thu Sep 15 12:31:40 PDT 2005


Author: msmith
Date: 2005-09-15 12:31:38 -0700 (Thu, 15 Sep 2005)
New Revision: 10017

Modified:
   icecast/trunk/icecast/src/source.c
Log:
Fix deadlock when moving clients. Thanks to oddsock for producing a testcase and
backtrace, and karl for fixing my brain


Modified: icecast/trunk/icecast/src/source.c
===================================================================
--- icecast/trunk/icecast/src/source.c	2005-09-14 17:55:05 UTC (rev 10016)
+++ icecast/trunk/icecast/src/source.c	2005-09-15 19:31:38 UTC (rev 10017)
@@ -340,7 +340,9 @@
     {
         client_t *client;
 
-        /* we need to move the client and pending trees */
+        /* we need to move the client and pending trees - we must take the
+         * locks in this order to avoid deadlocks */
+        avl_tree_wlock (source->client_tree);
         avl_tree_wlock (source->pending_tree);
 
         if (source->on_demand == 0 && source->format == NULL)
@@ -381,7 +383,6 @@
             count++;
         }
 
-        avl_tree_wlock (source->client_tree);
         while (1)
         {
             avl_node *node = avl_get_first (source->client_tree);
@@ -409,10 +410,12 @@
 
         source->listeners = 0;
         stats_event (source->mount, "listeners", "0");
-        avl_tree_unlock (source->client_tree);
 
     } while (0);
 
+    avl_tree_unlock (source->pending_tree);
+    avl_tree_unlock (source->client_tree);
+
     /* see if we need to wake up an on-demand relay */
     if (dest->running == 0 && dest->on_demand && count)
     {
@@ -420,7 +423,6 @@
         slave_rebuild_mounts();
     }
 
-    avl_tree_unlock (source->pending_tree);
     avl_tree_unlock (dest->pending_tree);
     thread_mutex_unlock (&move_clients_mutex);
 }



More information about the commits mailing list