Date: Thu, 01 Feb 2001 12:07:25 -0800 (PST) From: John Baldwin <jhb@FreeBSD.org> To: Julian Elischer <julian@elischer.org> Cc: Matthew Emmerton <matt@gsicomp.on.ca>, freebsd-hackers@FreeBSD.org Subject: Re: Atomic bit operations Message-ID: <XFMail.010201120725.jhb@FreeBSD.org> In-Reply-To: <3A79B054.BB13FA83@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 01-Feb-01 Julian Elischer wrote: > John Baldwin wrote: >> > >> >> The current implementation for it can be found at >> http://www.FreeBSD.org/~jhb/patches/refcount.patch. It's all done with >> simple >> atomic operations right now. >> > > what I do at the moment is: > > do { > v = node->nd_refs; > } while (! atomic_cmpset_int(&node->nd_refs, v, v - 1)); > > if (v == 1) { /* we were the last */ > .......whatever needs to be done > } > > but I'd rather have something more 'direct' With the refcount api you just use this: if (refcount_release(&node->nd_refs)) { /* was the last */ refcount_destroy(&node->nd_refs); ..... } The ucred refcount's could benefit from this, for example, as well as the node and hook refcounts in netgraph I think. Using a refcount is this simple: refcount_t foo; /* start off with one reference when we create it */ refcount_init(&foo, 1); ... refcount_acquire(&foo); /* add another reference */ Then use release as noted above in places that release a reference. -- John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010201120725.jhb>