Thread (7 messages) 7 messages, 5 authors, 2015-01-31

spinlock variable protection

From: Matwey V. Kornilov <hidden>
Date: 2015-01-30 12:43:40

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help