Subject: Re: Atomic ops API
To: Jason Thorpe <thorpej@shagadelic.org>
From: Brian Ginsbach <ginsbach@NetBSD.org>
List: tech-kern
Date: 03/13/2007 15:53:19
On Tue, Mar 13, 2007 at 03:55:49PM +0900, SODA Noriyuki wrote:
> >>>>> On Mon, 12 Mar 2007 23:28:47 -0700,
> Jason Thorpe <thorpej@shagadelic.org> said:
>
> > There is one major difference, however. Solaris defines "cas" as
> > COMPARE-AND-SWAP, returning the previous value of the memory cell.
> > I have defined it as COMPARE-AND- STORE, returning true if the ops
> > succeeds, or false otherwise. The reason for this is because some
> > platforms will have extreme difficulty implementing
> > COMPARE-AND-SWAP, whereas COMPARE-AND-STORE is somewhat easier for
> > these platforms.
>
> In that case, the functions should use a different name instead of
> *_cas_*(), shouldn't they?
> e.g.
> *_csi_* (compare and store interlocked)?
> *_cs_* (compare and store)?
Not necessarily; I think that the IRIX atomic op API implements
COMPARE-AND-SWAP as Jason describes COMPARE-AND-STORE.
From IRIX <sys/atomic_ops.h>:
/*
* Exchange values in memory. test_and_set is unconditional.
* compare_and_swap is conditional, returning 1 and swapping if the
* memory value equals "old".
*/
int compare_and_swap_int(int *loc, int old, int new);