mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: noman pouigt <variksla@gmail.com>
Cc: rostedt@goodmis.org, rusty@rustcorp.com.au,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Subject: Re: atomic read and increment question
Date: Tue, 18 Mar 2014 05:52:56 -0700	[thread overview]
Message-ID: <20140318125256.GJ4420@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAES_P+-FDQKQSSSdJBY0ivGJtHOA6K4rYSy7z20HowUUVcHdJQ@mail.gmail.com>

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


      parent reply	other threads:[~2014-03-18 12:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18  8:26 noman pouigt
2014-03-18 11:10 ` Clemens Ladisch
2014-03-18 12:52 ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140318125256.GJ4420@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=variksla@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome