On Mon, 11 Mar 2002, Ian Holsman wrote:
> hi.
> I'm not sure if this is the right spot to ask,
> but I'd like to see freebsd return a value on it's
> add/subtract atomic functions.
>
> is this hard to implement?
>
> is there a reason not to ?
>
Because many platforms (including the x86) implement addition and
subtraction instructions which modify the value in-place (whether in memory
or in a register). To get the behaviour you desire, you can build your own
routine using the existing atomic operations like so (not actually tested):
static inline int
atomic_readandadd_int(int *P, int V)
{
register int orig;
register int new;
do {
orig = *P;
new = orig + V;
} while (!atomic_cmpset_int(P, orig, new);
return (orig);
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message