From owner-freebsd-arch Wed Mar 27 21: 3:45 2002 Delivered-To: freebsd-arch@freebsd.org Received: from angelica.unixdaemons.com (angelica.unixdaemons.com [209.148.64.135]) by hub.freebsd.org (Postfix) with ESMTP id 97F4637B405 for ; Wed, 27 Mar 2002 21:03:41 -0800 (PST) Received: from angelica.unixdaemons.com (bmilekic@localhost.unixdaemons.com [127.0.0.1]) by angelica.unixdaemons.com (8.12.2/8.12.1) with ESMTP id g2S52fJX095453; Thu, 28 Mar 2002 00:02:41 -0500 (EST) X-Authentication-Warning: angelica.unixdaemons.com: Host bmilekic@localhost.unixdaemons.com [127.0.0.1] claimed to be angelica.unixdaemons.com Received: (from bmilekic@localhost) by angelica.unixdaemons.com (8.12.2/8.12.1/Submit) id g2S52eYf095442; Thu, 28 Mar 2002 00:02:40 -0500 (EST) (envelope-from bmilekic) Date: Thu, 28 Mar 2002 00:02:40 -0500 From: Bosko Milekic To: Julian Elischer Cc: arch@FreeBSD.ORG Subject: Re: SMP safe reference counting Message-ID: <20020328000240.A94897@unixdaemons.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: ; from julian@elischer.org on Wed, Mar 27, 2002 at 12:10:36PM -0800 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I don't think we really need a ref. count API, per-se. I can think of several places that may need to do ref. counting but wouldn't want to do it with a bus-locked instruction because their reference counter(s) are already protected by an existing mutex. -Bosko On Wed, Mar 27, 2002 at 12:10:36PM -0800, Julian Elischer wrote: > > [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-arch" in the body of the message > -- Bosko Milekic bmilekic@unixdaemons.com bmilekic@FreeBSD.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message