Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 May 2002 16:58:09 -0400 (EDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Alfred Perlstein <bright@mu.org>
Cc:        freebsd-arch@freebsd.org, Archie Cobbs <archie@dellroad.org>
Subject:   Re: question about atomic.h
Message-ID:  <XFMail.20020521165809.jhb@FreeBSD.org>
In-Reply-To: <20020521204318.GJ54960@elvis.mu.org>

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

On 21-May-2002 Alfred Perlstein wrote:
> * Archie Cobbs <archie@dellroad.org> [020521 13:30] wrote:
>> 
>> With atomic_subtract_int() returning void, there's no way to do
>> that without acquiring the mutex, because you can't atomically
>> decrement *and* read the reference count.
> 
> Check the mbuf subsystem for the way they do the atomic "decerement
> and let me know if it went to zero" operation.
> 
> it's something like atomic_int_acq or something. :)

You can use an atomic_cmpset loop, but it would be nice to have a
atomic_fetchadd() that did the add and returned the value.  We
can't return that value using normal x86 'addl %eax,[foo_mem]' since
there would be a race to read the value at foo_mem to return it
again.

On x86 we can use the 486+ xadd instruction to do this, but that
is what atomic_fetchadd() would basically be.  However, this
could be used to implement a little refcount API that would remove
the need for mutexes that just protect simple refcounts.  It's on
the todo list (well, should be.)

-- 

John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"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.20020521165809.jhb>