Date: Tue, 12 Dec 2000 12:24:50 -0800 (PST) From: John Baldwin <jhb@FreeBSD.org> To: arch@FreeBSD.org Subject: An opaque refcount type Message-ID: <XFMail.001212122450.jhb@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
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 <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-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.001212122450.jhb>