kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: matwey.kornilov@gmail.com (Matwey V. Kornilov)
To: kernelnewbies@lists.kernelnewbies.org
Subject: spinlock variable protection
Date: Fri, 30 Jan 2015 15:43:40 +0300	[thread overview]
Message-ID: <mafu9s$mhn$1@ger.gmane.org> (raw)

Hi,

I have the following code

         int ret = 0;
         unsigned long irqflags;

         spin_lock_irqsave(&lock, irqflags);

         //...
         ret = hdl->count;
         //...

         spin_unlock_irqrestore(&lock, irqflags);
         return ret;

I would like to be sure, that ret will not be optimized out. I think 
compiler can convert the code to equivalent:

         unsigned long irqflags;

         spin_lock_irqsave(&lock, irqflags);

         //...
         //...

         spin_unlock_irqrestore(&lock, irqflags);
         return hdl->count;

But this is not what I want, because I use lock to protect hdl and want 
to return hdl->count value as it was in protected section.

             reply	other threads:[~2015-01-30 12:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-30 12:43 Matwey V. Kornilov [this message]
2015-01-30 13:52 ` spinlock variable protection buyitian
2015-01-30 14:20   ` Matwey V. Kornilov
2015-01-30 15:23     ` Malte Vesper
2015-01-30 15:29       ` Matwey V. Kornilov
2015-01-31  6:23       ` Arun KS
2015-01-31 12:04     ` Nicholas Mc Guire

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='mafu9s$mhn$1@ger.gmane.org' \
    --to=matwey.kornilov@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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;
as well as URLs for NNTP newsgroup(s).