summaryrefslogtreecommitdiff
path: root/libnetfs/release-peropen.c
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2016-02-07 01:33:00 -0500
committerJustus Winter <4winter@informatik.uni-hamburg.de>2016-02-07 15:42:23 +0100
commitafea5285b0e40b68f97b47f0f0edc471b554fb34 (patch)
treed050d0e9738372db680d1d4036c63bd7d6de6cfb /libnetfs/release-peropen.c
parent35ae0168bbdae2eb7029262f49d394046a67860f (diff)
Use refcount_t for peropen reference counting in libnetfs.
* libnetfs/netfs.h: Use refcount_t. * libnetfs/make-peropen.c: Initialize to 1 with refcount_init just like in libdiskfs. * libnetfs/make-protid.c: Don't increment the count here. Do it like libdiskfs. * libnetfs/io-duplicate.c: Add refcount_ref since netfs_make_protid no longer increments the refcount. * libnetfs/io-reauthenticate.c: Likewise. * libnetfs/io-restrict-auth.c: Likewise. * libnetfs/release-peropen.c: Dereference without locking.
Diffstat (limited to 'libnetfs/release-peropen.c')
-rw-r--r--libnetfs/release-peropen.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/libnetfs/release-peropen.c b/libnetfs/release-peropen.c
index c206b438..01af97dd 100644
--- a/libnetfs/release-peropen.c
+++ b/libnetfs/release-peropen.c
@@ -24,29 +24,27 @@
void
netfs_release_peropen (struct peropen *po)
{
+ if (refcount_deref (&po->refcnt) > 0)
+ return;
+
pthread_mutex_lock (&po->np->lock);
- if (--po->refcnt)
- pthread_mutex_unlock (&po->np->lock);
- else
- {
- if (po->root_parent)
- mach_port_deallocate (mach_task_self (), po->root_parent);
+ if (po->root_parent)
+ mach_port_deallocate (mach_task_self (), po->root_parent);
- if (po->shadow_root && po->shadow_root != po->np)
- {
- pthread_mutex_lock (&po->shadow_root->lock);
- netfs_nput (po->shadow_root);
- }
- if (po->shadow_root_parent)
- mach_port_deallocate (mach_task_self (), po->shadow_root_parent);
+ if (po->shadow_root && po->shadow_root != po->np)
+ {
+ pthread_mutex_lock (&po->shadow_root->lock);
+ netfs_nput (po->shadow_root);
+ }
+ if (po->shadow_root_parent)
+ 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);
+ if (po->lock_status != LOCK_UN)
+ fshelp_acquire_lock (&po->np->userlock, &po->lock_status,
+ &po->np->lock, LOCK_UN);
- netfs_nput (po->np);
+ netfs_nput (po->np);
- free (po->path);
- free (po);
- }
+ free (po->path);
+ free (po);
}