* atomic read and increment question
@ 2014-03-18 8:26 noman pouigt
2014-03-18 11:10 ` Clemens Ladisch
2014-03-18 12:52 ` Paul E. McKenney
0 siblings, 2 replies; 3+ messages in thread
From: noman pouigt @ 2014-03-18 8:26 UTC (permalink / raw)
To: paulmck, rostedt, rusty, gregkh; +Cc: linux-kernel
Hello,
I looked through the documentation for atomic
operations but couldn't find out the api for following
operation:
x = 1;
temp = atomic_read_increment(x);
so basically this will read the old value of x in temp
and then increment x.
so temp = 1 and x = 2.
Is this api already available?
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: atomic read and increment question
2014-03-18 8:26 atomic read and increment question noman pouigt
@ 2014-03-18 11:10 ` Clemens Ladisch
2014-03-18 12:52 ` Paul E. McKenney
1 sibling, 0 replies; 3+ messages in thread
From: Clemens Ladisch @ 2014-03-18 11:10 UTC (permalink / raw)
To: noman pouigt; +Cc: linux-kernel
noman pouigt wrote:
> x = 1;
> temp = atomic_read_increment(x);
atomic_set(&x, 1);
temp = atomic_inc_return(&x);
> I looked through the documentation for atomic
> operations but couldn't find out the api
Not everything is fully documented.
Look through include/asm-generic/atomic.h.
Regards,
Clemens
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: atomic read and increment question
2014-03-18 8:26 atomic read and increment question noman pouigt
2014-03-18 11:10 ` Clemens Ladisch
@ 2014-03-18 12:52 ` Paul E. McKenney
1 sibling, 0 replies; 3+ messages in thread
From: Paul E. McKenney @ 2014-03-18 12:52 UTC (permalink / raw)
To: noman pouigt; +Cc: rostedt, rusty, gregkh, linux-kernel
On Tue, Mar 18, 2014 at 01:26:12AM -0700, noman pouigt wrote:
> Hello,
>
> I looked through the documentation for atomic
> operations but couldn't find out the api for following
> operation:
>
> x = 1;
> temp = atomic_read_increment(x);
>
> so basically this will read the old value of x in temp
> and then increment x.
>
> so temp = 1 and x = 2.
>
> Is this api already available?
You want atomic_inc_return(). It returns the new value rather than the
old value, but you can do the following:
temp = atomic_inc_return(&x) - 1;
Thanx, Paul
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-18 12:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18 8:26 atomic read and increment question noman pouigt
2014-03-18 11:10 ` Clemens Ladisch
2014-03-18 12:52 ` Paul E. McKenney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).