mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +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 "transmission.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "platform.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL };
|
static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL };
|
||||||
|
|
||||||
static tr_list * recycled_nodes = 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*
|
static tr_list*
|
||||||
node_alloc (void)
|
node_alloc (void)
|
||||||
{
|
{
|
||||||
|
@ -29,8 +41,10 @@ node_alloc (void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
tr_lockLock (getRecycledNodesLock ());
|
||||||
ret = recycled_nodes;
|
ret = recycled_nodes;
|
||||||
recycled_nodes = recycled_nodes->next;
|
recycled_nodes = recycled_nodes->next;
|
||||||
|
tr_lockUnlock (getRecycledNodesLock ());
|
||||||
}
|
}
|
||||||
|
|
||||||
*ret = TR_LIST_CLEAR;
|
*ret = TR_LIST_CLEAR;
|
||||||
|
@ -43,8 +57,10 @@ node_free (tr_list* node)
|
||||||
if (node != NULL)
|
if (node != NULL)
|
||||||
{
|
{
|
||||||
*node = TR_LIST_CLEAR;
|
*node = TR_LIST_CLEAR;
|
||||||
|
tr_lockLock (getRecycledNodesLock ());
|
||||||
node->next = recycled_nodes;
|
node->next = recycled_nodes;
|
||||||
recycled_nodes = node;
|
recycled_nodes = node;
|
||||||
|
tr_lockUnlock (getRecycledNodesLock ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue