Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Mar 2002 00:02:40 -0500
From:      Bosko Milekic <bmilekic@unixdaemons.com>
To:        Julian Elischer <julian@elischer.org>
Cc:        arch@FreeBSD.ORG
Subject:   Re: SMP safe reference counting
Message-ID:  <20020328000240.A94897@unixdaemons.com>
In-Reply-To: <Pine.BSF.4.21.0203271150430.47944-100000@InterJet.elischer.org>; from julian@elischer.org on Wed, Mar 27, 2002 at 12:10:36PM -0800
References:  <Pine.BSF.4.21.0203271150430.47944-100000@InterJet.elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help

  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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020328000240.A94897>