Subject: Re: Test and set (was Re: postgreSQL)
To: Bill Sommerfeld <sommerfeld@orchard.arlington.ma.us>
From: Simon Burge <simonb@netbsd.org>
List: tech-kern
Date: 05/28/1999 17:36:43
Bill Sommerfeld wrote:

> There are a variety of different atomic instructions out there.

Yeah, as I found out.  A bit of time on AltaVista didn't show many
people doing the same thing :-)

> To throw out one of the outliers in this space, PA has "compare and
> clear" as its atomic memory access instruction.  This is sort of like
> "test and set", except that the "set" state is zero, and the "unset"
> state is non-zero.
> 
> To make life even more interesting, semaphores have to be 16-byte
> aligned, though they're only 4 bytes wide.
> 
> I suspect a "sufficiently MI" interface to an "atomic_op()"-like thing
> would have to abstract what the "set" and "reset" values and type look
> like:
> 
>     atomic_value_t v1 = ATOMIC_INIT_RESET;
>     atomic_value_t v2 = ATOMIC_INIT_SET;
> 
>     int atomic_set(atomic_value_t *v);
> 	set *v; return 1 if it wasn't already set.
>     void atomic_reset(atomic_value_t *v);
> 	reset *v.
>     int atomic_isset(atomic_value_t *v);
> 	return 1 if *v is set, otherwise 0.

And this interface would live in <atomic.h> or <sys/atomic.h>?  If
we need a kernel implementation (as for older MIPS chips), then
<sys/atomic.h> would be the way to go...

I'll put together a full proposal.

Simon.