All of lore.kernel.org
 help / color / mirror / Atom feed
From: buyitian@gmail.com (buyitian)
To: kernelnewbies@lists.kernelnewbies.org
Subject: spinlock variable protection
Date: Fri, 30 Jan 2015 21:52:07 +0800	[thread overview]
Message-ID: <A827E844-3767-4BE6-A45F-B3E1CC615E36@gmail.com> (raw)
In-Reply-To: <mafu9s$mhn$1@ger.gmane.org>



> ? 2015?1?30??20:43?"Matwey V. Kornilov" <matwey.kornilov@gmail.com> ???
> 
> 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.
> 
> 
Please check the assembly code to double confirm the GCC behavior.
Why will GCC change the order as what you mentioned? Only assembly code can tell you.



> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2015-01-30 13:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-30 12:43 spinlock variable protection Matwey V. Kornilov
2015-01-30 13:52 ` buyitian [this message]
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=A827E844-3767-4BE6-A45F-B3E1CC615E36@gmail.com \
    --to=buyitian@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.