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. --- tmpfs/node.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'tmpfs') diff --git a/tmpfs/node.c b/tmpfs/node.c index 428b6d92..2a4489c2 100644 --- a/tmpfs/node.c +++ b/tmpfs/node.c @@ -40,7 +40,6 @@ static unsigned int gen; reference. */ struct node *all_nodes; static size_t all_nodes_nr_items; -/* all_nodes_lock must be acquired before diskfs_node_refcnt_lock. */ pthread_rwlock_t all_nodes_lock = PTHREAD_RWLOCK_INITIALIZER; error_t @@ -267,7 +266,7 @@ diskfs_node_iterate (error_t (*fun) (struct node *)) /* We acquire a hard reference for node, but without using diskfs_nref. We do this so that diskfs_new_hardrefs will not get called. */ - node->references++; + refcounts_ref (&node->refcounts, NULL); } pthread_rwlock_unlock (&all_nodes_lock); @@ -300,14 +299,10 @@ diskfs_try_dropping_softrefs (struct node *np) if (np->cache_id != 0) { /* Check if someone reacquired a reference. */ - unsigned int references; - pthread_spin_lock (&diskfs_node_refcnt_lock); - references = np->references; - pthread_spin_unlock (&diskfs_node_refcnt_lock); - - /* An additional reference is acquired by libdiskfs across calls - to diskfs_try_dropping_softrefs. */ - if (references > 1) + struct references result; + refcounts_references (&np->refcounts, &result); + + if (result.hard > 0) { /* A reference was reacquired. It's fine, we didn't touch anything yet. */ -- cgit v1.2.3