From owner-freebsd-hackers Thu Feb 1 12: 8:38 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from meow.osd.bsdi.com (meow.osd.bsdi.com [204.216.28.88]) by hub.freebsd.org (Postfix) with ESMTP id 8DECC37B69F for ; Thu, 1 Feb 2001 12:08:13 -0800 (PST) Received: from laptop.baldwin.cx (john@jhb-laptop.osd.bsdi.com [204.216.28.241]) by meow.osd.bsdi.com (8.11.1/8.9.3) with ESMTP id f11K1g354355; Thu, 1 Feb 2001 12:01:42 -0800 (PST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <3A79B054.BB13FA83@elischer.org> Date: Thu, 01 Feb 2001 12:07:25 -0800 (PST) From: John Baldwin To: Julian Elischer Subject: Re: Atomic bit operations Cc: Matthew Emmerton , freebsd-hackers@FreeBSD.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 -- 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