From owner-freebsd-arch Tue Dec 12 12:24:51 2000 From owner-freebsd-arch@FreeBSD.ORG Tue Dec 12 12:24:50 2000 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from pike.osd.bsdi.com (pike.osd.bsdi.com [204.216.28.222]) by hub.freebsd.org (Postfix) with ESMTP id D259137B400 for ; Tue, 12 Dec 2000 12:24:49 -0800 (PST) Received: from laptop.baldwin.cx (john@jhb-laptop.osd.bsdi.com [204.216.28.241]) by pike.osd.bsdi.com (8.11.1/8.9.3) with ESMTP id eBCKOjE95641 for ; Tue, 12 Dec 2000 12:24:45 -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 Date: Tue, 12 Dec 2000 12:24:50 -0800 (PST) From: John Baldwin To: arch@FreeBSD.org Subject: An opaque refcount type Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Here's another bikeshed war for everyone to get in on: I've implemented a relatively light weight and very simple opaque reference counter. It defines an opaque refcount_t type. In the INVARIANTS case, this maps to a structure that contains an integer and a mutex. The mutex is used to protect the integer count as well as several KASSERT()'s. In the non-INVARIANTS case, it maps to a single integer on all of our current platforms (x86, alpha, ia64) and is managed via atomic operations. It defines a rather simple API: void refcount_init(refcount_t *count, u_int value) - Initializes the reference counter and sets its inital count to 'value'. void refcount_destroy(refcount_t *count) - Cleans up any internals used in a refcount, frees resources, etc. void refcount_acquire(refcount_t *count) - Atomically bump the reference count by one. int refcount_release(refcount_t *count) - Atomically decerement the reference count by one and return true if the count drops to zero. The patch to do all this is found at http://www.FreeBSD.org/~jhb/patches/refcount.patch. If this goes in I'll work up a manpage to go along with it as well.. -- 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-arch" in the body of the message