Subject: Re: Atomic operations for NetBSD
To: tech-kern@NetBSD.org, Tonnerre <tonnerre@thundrix.ch>
From: David Laight <david@l8s.co.uk>
List: tech-kern
Date: 06/12/2005 20:39:15
On Sun, Jun 12, 2005 at 06:46:59PM +0200, Joerg Sonnenberger wrote:
> On Sat, Jun 11, 2005 at 11:13:08AM +0100, David Laight wrote:
> > Actually I suspect that the code fragments you showed are all just as
> > expensive as using a lock - you are just using the data item itself
> > as the lock.
> 
> Depends on which costs you are measuring. It has the advantage of
> being non-blocking (read: one thread always advances and e.g. an ISR
> can't block the access). Speaking about bus time, if all you need is
> ONE atomic update, it is faster, since a mutex normally needs TWO
> atomic operations (lock + unlock).

I think you'll find that the unlock operation needs to be neither
atomic, nor a synchronous/locked bus cycle.  An simple update of the value
in the local cpus data cache will suffice - a subsequent read operation
by a different cpu will snoop the data.

	David

-- 
David Laight: david@l8s.co.uk