From owner-freebsd-smp Wed Mar 27 12:20:52 2002 Delivered-To: freebsd-smp@freebsd.org Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by hub.freebsd.org (Postfix) with ESMTP id 111C737B425; Wed, 27 Mar 2002 12:20:10 -0800 (PST) Received: from InterJet.elischer.org ([12.232.206.8]) by rwcrmhc52.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020327202009.WPNJ1147.rwcrmhc52.attbi.com@InterJet.elischer.org>; Wed, 27 Mar 2002 20:20:09 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id MAA48226; Wed, 27 Mar 2002 12:10:37 -0800 (PST) Date: Wed, 27 Mar 2002 12:10:36 -0800 (PST) From: Julian Elischer To: arch@freebsd.org Cc: smp@freeBSD.org Subject: SMP safe reference counting Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org [please remove -smp from your reply] Once again on the SMP list a lock is being used to make a reference count safe. I'd like to re-raise the issue of a safe reference counting fascility. what would be the semantics? typedef volatile u_int ref_cnt; typedef void ref_free(void *); reference_add(ref_cnt *); reference_drop(ref_cnt *, ref_free *, void *); __inline void reference_add(ref_cnt *cnt) { atomic_inc(cnt); } /* Note I use the non-existing "atomic_inc()". I think we should have this as its SO COMMONLY used. */ __inline void reference_drop(ref_cnt *cnt, ref_free *fn. void * arg) { int newcount; int oldcount; do { newcount = (oldcount = *cnt) - 1; } while (atomic_cmp_and_set(cnt, oldcount, newcount) == ACS_FAILED); } /* I can't remember off the top of my head the cmp-and-set command */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message