lkml.org 
[lkml]   [2014]   [Mar]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: atomic read and increment question
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



\
 
 \ /
  Last update: 2014-03-18 14:41    [W:0.063 / U:0.616 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site