mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
make accessing tr_list's recycle nodes threadsafe. patch by mike.did, fixes #5352
This commit is contained in:
parent
5661aaad5e
commit
d112a813e9
1 changed files with 16 additions and 0 deletions
|
@ -12,12 +12,24 @@
|
|||
|
||||
#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 ());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue