summaryrefslogtreecommitdiff
path: root/libdiskfs/node-nrele.c
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2016-02-14 18:37:16 -0500
committerJustus Winter <justus@gnupg.org>2016-02-15 01:13:19 +0100
commit0f6a5081d875051e1b6275096d25332e66f0458c (patch)
tree03c55df08101f2900d8ca36fb510133f373a5a5a /libdiskfs/node-nrele.c
parent63ac03bc069b81559b04596d6b337880c3351700 (diff)
libdiskfs: fix and improve locking in nrefs/nput.
* libnetfs/node-nput.c: Do not unlock the node since it will be unlocked later. * libnetfs/node-nrele.c: Do not lock the node twice if not needed.
Diffstat (limited to 'libdiskfs/node-nrele.c')
-rw-r--r--libdiskfs/node-nrele.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libdiskfs/node-nrele.c b/libdiskfs/node-nrele.c
index d9628469..a96d1346 100644
--- a/libdiskfs/node-nrele.c
+++ b/libdiskfs/node-nrele.c
@@ -28,6 +28,7 @@
void
diskfs_nrele (struct node *np)
{
+ int locked = FALSE;
struct references result;
/* While we call the diskfs_try_dropping_softrefs, we need to hold
@@ -37,6 +38,7 @@ diskfs_nrele (struct node *np)
if (result.hard == 0)
{
+ locked = TRUE;
pthread_mutex_lock (&np->lock);
diskfs_lost_hardrefs (np);
if (!np->dn_stat.st_nlink)
@@ -49,7 +51,6 @@ diskfs_nrele (struct node *np)
hold a weak reference ourselves. */
diskfs_try_dropping_softrefs (np);
}
- pthread_mutex_unlock (&np->lock);
}
/* Finally get rid of our reference. */
@@ -57,7 +58,10 @@ diskfs_nrele (struct node *np)
if (result.hard == 0 && result.weak == 0)
{
- pthread_mutex_lock (&np->lock);
+ if (! locked)
+ pthread_mutex_lock (&np->lock);
diskfs_drop_node (np);
}
+ else if (locked)
+ pthread_mutex_unlock (&np->lock);
}