aboutsummaryrefslogtreecommitdiff
path: root/libtrivfs/protid-clean.c
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-06 19:07:13 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-26 13:17:16 +0200
commit1d1da90042d2ee7a8215dc6291b54bc1ebe59fe4 (patch)
tree54c00f70a5703b40bb8243a6d76afd024c50cdaf /libtrivfs/protid-clean.c
parent5b039a12bf5cfc9c65b8e169ed4503e306f971f3 (diff)
downloadhurd-1d1da90042d2ee7a8215dc6291b54bc1ebe59fe4.tar.gz
hurd-1d1da90042d2ee7a8215dc6291b54bc1ebe59fe4.tar.bz2
hurd-1d1da90042d2ee7a8215dc6291b54bc1ebe59fe4.zip
libtrivfs: lock-less reference counting for trivfs_peropen objects
* libtrivfs/trivfs.h (struct trivfs_peropen): Use refcount_t for field refcnt. (struct trivfs_control): Remove unused field lock. * libtrivfs/cntl-create.c (trivfs_create_control): Drop the mutex initialization. * libtrivfs/io-reauthenticate.c (trivfs_S_io_reauthenticate): Adjust accordingly. * libtrivfs/io-restrict-auth.c (trivfs_S_io_restrict_auth): Likewise. * libtrivfs/open.c (trivfs_open): Initialize refcnt. * libtrivfs/protid-clean.c (trivfs_clean_protid): Likewise. * libtrivfs/protid-dup.c (trivfs_protid_dup): Likewise.
Diffstat (limited to 'libtrivfs/protid-clean.c')
-rw-r--r--libtrivfs/protid-clean.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/libtrivfs/protid-clean.c b/libtrivfs/protid-clean.c
index f98da6a5..86fbc191 100644
--- a/libtrivfs/protid-clean.c
+++ b/libtrivfs/protid-clean.c
@@ -31,19 +31,26 @@ trivfs_clean_protid (void *arg)
(*trivfs_protid_destroy_hook) (cred);
/* If we hold the only reference to the peropen, try to get rid of it. */
- pthread_mutex_lock (&cntl->lock);
- if (cred->po->refcnt == 1 && trivfs_peropen_destroy_hook)
+ if (trivfs_peropen_destroy_hook)
{
- pthread_mutex_unlock (&cntl->lock);
- (*trivfs_peropen_destroy_hook) (cred->po);
- pthread_mutex_lock (&cntl->lock);
+ if (refcount_deref (&cred->po->refcnt) == 0)
+ {
+ /* Reaquire a reference while we call the hook. */
+ refcount_ref (&cred->po->refcnt);
+ (*trivfs_peropen_destroy_hook) (cred->po);
+ if (refcount_deref (&cred->po->refcnt) == 0)
+ {
+ ports_port_deref (cntl);
+ free (cred->po);
+ }
+ }
}
- if (--cred->po->refcnt == 0)
- {
- ports_port_deref (cntl);
- free (cred->po);
- }
- pthread_mutex_unlock (&cntl->lock);
+ else
+ if (refcount_deref (&cred->po->refcnt) == 0)
+ {
+ ports_port_deref (cntl);
+ free (cred->po);
+ }
iohelp_free_iouser (cred->user);