]> granicus.if.org Git - transmission/commitdiff
make accessing tr_list's recycle nodes threadsafe. patch by mike.did, fixes #5352
authorJordan Lee <jordan@transmissionbt.com>
Sun, 25 Aug 2013 16:27:19 +0000 (16:27 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 25 Aug 2013 16:27:19 +0000 (16:27 +0000)
libtransmission/list.c

index 3d3e5169955422b5c561971a65eb7bea824fd5a2..e39749011380cf97f951278b33f3784e7e64357d 100644 (file)
 
 #include "transmission.h"
 #include "list.h"
+#include "platform.h"
 #include "utils.h"
 
 static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL };
 
 static tr_list * recycled_nodes = NULL;
 
+static tr_lock*
+getRecycledNodesLock (void)
+{
+  static tr_lock * l = NULL;
+
+  if (!l)
+    l = tr_lockNew ();
+
+  return l;
+}
+
 static tr_list*
 node_alloc (void)
 {
@@ -29,8 +41,10 @@ node_alloc (void)
     }
   else
     {
+      tr_lockLock (getRecycledNodesLock ());
       ret = recycled_nodes;
       recycled_nodes = recycled_nodes->next;
+      tr_lockUnlock (getRecycledNodesLock ());
     }
 
   *ret = TR_LIST_CLEAR;
@@ -43,8 +57,10 @@ node_free (tr_list* node)
   if (node != NULL)
     {
       *node = TR_LIST_CLEAR;
+      tr_lockLock (getRecycledNodesLock ());
       node->next = recycled_nodes;
       recycled_nodes = node;
+      tr_lockUnlock (getRecycledNodesLock ());
     }
 }