All of lore.kernel.org
 help / color / mirror / Atom feed
* spinlock variable protection
@ 2015-01-30 12:43 Matwey V. Kornilov
  2015-01-30 13:52 ` buyitian
  0 siblings, 1 reply; 7+ messages in thread
From: Matwey V. Kornilov @ 2015-01-30 12:43 UTC (permalink / raw)
  To: kernelnewbies

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-01-31 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-30 12:43 spinlock variable protection Matwey V. Kornilov
2015-01-30 13:52 ` 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

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.