From dc00a94df4a06764d822b29cbf35b532343821c8 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Tue, 6 May 2014 18:58:10 +0200 Subject: 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. --- libdiskfs/peropen-rele.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'libdiskfs/peropen-rele.c') 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); -- cgit v1.2.3