From ea1d2b0045e2c2ad82a2162a58f9fc36f9d07b20 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Sun, 31 May 2015 15:16:41 +0200 Subject: core: add "gf_ref_t" for common refcounting structures Checks for compiler supported atomic operations comes from client_t.h. An example usage of this change can be found in adding reference counting to "struct auth_cache_entry" in http://review.gluster.org/11023 Basic usage looks like this: #include "refcount.h" struct my_struct { GF_REF_DECL; ... /* more members */ } void my_destructor (void *data) { struct my_struct *my_ptr = (struct my_struct *) data; ... /* do some more cleanups */ GF_FREE (my_ptr); } void init_ptr (struct parent *parent) { struct my_struct *my_ptr = malloc (sizeof (struct my_struct)); GF_REF_INIT (my_ptr, my_destructor); /* refcount is set to 1 */ ... /* my_ptr probably gets added to some parent structure */ parent_add_ptr (parent, my_ptr); } void do_something (struct parent *parent) { struct my_struct *my_ptr = NULL; /* likely need to lock parent, depends on its access pattern */ my_ptr = parent_remove_first_ptr (parent); /* unlock parent */ ... /* do something */ GF_REF_PUT (my_ptr); /* calls my_destructor on refcount = 0 */ } URL: http://thread.gmane.org/gmane.comp.file-systems.gluster.devel/11202 Change-Id: Idb98a5861a44c31676108ed8876db12c320912ef BUG: 1228157 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/11022 Reviewed-by: Xavier Hernandez Reviewed-by: Krishnan Parthasarathi Tested-by: Gluster Build System Tested-by: NetBSD Build System --- libglusterfs/src/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libglusterfs/src/Makefile.am') diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 8a13305ea03..fd6d275e8fa 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -22,7 +22,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \ $(CONTRIBDIR)/rbtree/rb.c rbthash.c store.c latency.c \ graph.c syncop.c graph-print.c trie.c run.c options.c fd-lk.c \ circ-buff.c event-history.c gidcache.c ctx.c client_t.c event-poll.c \ - event-epoll.c syncop-utils.c cluster-syncop.c \ + event-epoll.c syncop-utils.c cluster-syncop.c refcount.c \ $(CONTRIBDIR)/libgen/basename_r.c \ $(CONTRIBDIR)/libgen/dirname_r.c $(CONTRIBDIR)/stdlib/gf_mkostemp.c \ strfd.c parse-utils.c $(CONTRIBDIR)/mount/mntent.c \ @@ -40,7 +40,7 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h timespec. gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h \ checksum.h daemon.h $(CONTRIBDIR)/rbtree/rb.h store.h\ rbthash.h iatt.h latency.h mem-types.h syncop.h cluster-syncop.h \ - graph-utils.h trie.h \ + graph-utils.h trie.h refcount.h \ run.h options.h lkowner.h fd-lk.h circ-buff.h event-history.h \ gidcache.h client_t.h glusterfs-acl.h glfs-message-id.h \ template-component-messages.h strfd.h syncop-utils.h parse-utils.h \ -- cgit