Date: Mon, 11 Mar 2002 12:47:13 -0800 (PST) From: Kelly Yancey <kbyanc@posi.net> To: Ian Holsman <freebsd@holsman.net> Cc: freebsd-smp@FreeBSD.ORG Subject: Re: feature request -- atomic add/dec return the old value Message-ID: <20020311122542.J47075-100000@gateway.posi.net> In-Reply-To: <3C8CD9F5.50507@holsman.net>
index | next in thread | previous in thread | raw e-mail
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
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020311122542.J47075-100000>
