From c16eed2cb64089bf7d958db0fe85352f4ceefb4d Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Wed, 14 May 2014 11:19:35 +0200 Subject: libdiskfs: lock-less reference counting of nodes * libdiskfs/diskfs.h (struct node): Use refcounts_t for reference counting. (diskfs_node_refcnt_lock): Remove. (diskfs_node_norefs,diskfs_drop_node): Change comments accordingly. * libdiskfs/init-init.c: Adjust accordingly. * libdiskfs/node-drop.c: Likewise. * libdiskfs/node-make.c: Likewise. * libdiskfs/node-nput.c: Likewise. * libdiskfs/node-nputl.c: Likewise. * libdiskfs/node-nref.c: Likewise. * libdiskfs/node-nrefl.c: Likewise. * libdiskfs/node-nrele.c: Likewise. * libdiskfs/node-nrelel.c: Likewise. * ext2fs/inode.c: Likewise. * fatfs/inode.c: Likewise. * isofs/inode.c: Likewise. * tmpfs/node.c: Likewise. * doc/hurd.texi: Likewise. --- libdiskfs/node-drop.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'libdiskfs/node-drop.c') diff --git a/libdiskfs/node-drop.c b/libdiskfs/node-drop.c index 83eb5909..455031bc 100644 --- a/libdiskfs/node-drop.c +++ b/libdiskfs/node-drop.c @@ -31,9 +31,8 @@ free_modreqs (struct modreq *mr) } -/* Node NP now has no more references; clean all state. The - diskfs_node_refcnt_lock must be held, and will be released - upon return. NP must be locked. */ +/* Node NP now has no more references; clean all state. NP must be + locked. */ void diskfs_drop_node (struct node *np) { @@ -60,8 +59,7 @@ diskfs_drop_node (struct node *np) and an nput. The next time through, this routine will notice that the size is zero, and not have to do anything. */ - np->references++; - pthread_spin_unlock (&diskfs_node_refcnt_lock); + refcounts_unsafe_ref (&np->refcounts, NULL); diskfs_truncate (np, 0); /* Force allocsize to zero; if truncate consistently fails this @@ -93,6 +91,7 @@ diskfs_drop_node (struct node *np) assert (!np->sockaddr); + pthread_mutex_unlock(&np->lock); + pthread_mutex_destroy(&np->lock); diskfs_node_norefs (np); - pthread_spin_unlock (&diskfs_node_refcnt_lock); } -- cgit v1.2.3