aboutsummaryrefslogtreecommitdiff
path: root/libdiskfs/peropen-rele.c
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-06 18:58:10 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-26 11:18:13 +0200
commitdc00a94df4a06764d822b29cbf35b532343821c8 (patch)
treee7564cd1b9db1e8019cf1d4a458922c0de245b04 /libdiskfs/peropen-rele.c
parentb793108b09138edf0a963d9e3107eb400ee27011 (diff)
downloadhurd-dc00a94df4a06764d822b29cbf35b532343821c8.tar.gz
hurd-dc00a94df4a06764d822b29cbf35b532343821c8.tar.bz2
hurd-dc00a94df4a06764d822b29cbf35b532343821c8.zip
libdiskfs: lock-less reference counting for peropen objects
* libdiskfs/diskfs.h (struct peropen): Use refcount_t for field refcnt. * libdiskfs/peropen-make.c (diskfs_make_peropen): Initialize refcnt. * libdiskfs/peropen-rele.c (diskfs_release_peropen): Adjust accordingly. * libdiskfs/protid-make.c (diskfs_start_protid): Likewise. Also, the node must no longer be locked, adjust comment accordingly. (diskfs_create_protid): Likewise.
Diffstat (limited to 'libdiskfs/peropen-rele.c')
-rw-r--r--libdiskfs/peropen-rele.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/libdiskfs/peropen-rele.c b/libdiskfs/peropen-rele.c
index d3f74921..877137bb 100644
--- a/libdiskfs/peropen-rele.c
+++ b/libdiskfs/peropen-rele.c
@@ -22,13 +22,8 @@
void
diskfs_release_peropen (struct peropen *po)
{
- pthread_mutex_lock (&po->np->lock);
-
- if (--po->refcnt)
- {
- pthread_mutex_unlock (&po->np->lock);
- return;
- }
+ if (refcount_deref (&po->refcnt) > 0)
+ return;
if (po->root_parent)
mach_port_deallocate (mach_task_self (), po->root_parent);
@@ -40,10 +35,14 @@ diskfs_release_peropen (struct peropen *po)
mach_port_deallocate (mach_task_self (), po->shadow_root_parent);
if (po->lock_status != LOCK_UN)
- fshelp_acquire_lock (&po->np->userlock, &po->lock_status,
- &po->np->lock, LOCK_UN);
-
- diskfs_nput (po->np);
+ {
+ pthread_mutex_lock (&po->np->lock);
+ fshelp_acquire_lock (&po->np->userlock, &po->lock_status,
+ &po->np->lock, LOCK_UN);
+ diskfs_nput (po->np);
+ }
+ else
+ diskfs_nrele (po->np);
free (po->path);
free (po);