From owner-freebsd-hackers Thu Feb 1 9:50:24 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from pike.osd.bsdi.com (unknown [204.216.28.222]) by hub.freebsd.org (Postfix) with ESMTP id E3E4237B6A2 for ; Thu, 1 Feb 2001 09:50:06 -0800 (PST) Received: from foo.osd.bsdi.com (root@foo.osd.bsdi.com [204.216.28.137]) by pike.osd.bsdi.com (8.11.1/8.9.3) with ESMTP id f11Hnmx53327; Thu, 1 Feb 2001 09:49:48 -0800 (PST) (envelope-from jhb@foo.osd.bsdi.com) Received: (from jhb@localhost) by foo.osd.bsdi.com (8.11.1/8.11.1) id f11HnEC13582; Thu, 1 Feb 2001 09:49:14 -0800 (PST) (envelope-from jhb) 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: <3A791493.FC414DEB@elischer.org> Date: Thu, 01 Feb 2001 09:49:14 -0800 (PST) Organization: BSD, Inc. From: John Baldwin To: Julian Elischer Subject: Re: Atomic bit operations Cc: freebsd-hackers@FreeBSD.org, Matthew Emmerton Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On 01-Feb-01 Julian Elischer wrote: > John Baldwin wrote: >> >> On 31-Jan-01 Matthew Emmerton wrote: >> > Hi all, >> > >> > I've taken a look around for an implementation of atomic bit operations in >> > FreeBSD (similar to Linux' asm/bitopt.h, which include clear_bit() and >> > test_and_set_bit()) but haven't found any. The only thing I've found are >> > the atomic clear/set/add/sub routines in machine/atomic.h. >> > >> > Do we have an implementation of atomic bit operations, and if we don't, >> > would we like some? >> >> Erm, atomic_set() sets's bits, and atomic_clear() clear's bits. Anything >> else >> you might need can be done with atomic_cmpset() anyways. Also, atomic >> operations are very hard to debug, esp. to check for race conditions, so >> there >> direct use is discouraged. Instead, use a higher level primitive such as a >> mutex or other appropriate lock. There is also talk of a potential abstract >> refcount type so that simple reference counts can be optimized, though that >> has >> been shot down thus far. > > by who?? I really want this.... Mostly Jason Evans, though Justin Gibbs pointed out that it won't work for all reference counts that one may need, and thus had a problem with having a refcont(9) API that didn't cover all possible refcounts. 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. -- 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