Re: spinlock variable protection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> 在 2015年1月30日,20:43,"Matwey V. Kornilov" <matwey.kornilov@xxxxxxxxx> 写道:
> 
> 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@xxxxxxxxxxxxxxxxx
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies





[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux