Re: volatile magic

thospel@mail.dma.be
24 Sep 1997 20:14:59 -0000


In article <m0xDa3p-0005FrC@lightning.swansea.linux.org.uk>,
alan@lxorguk.ukuu.org.uk (Alan Cox) writes:
>> A haven't found any cases in the scsi code where reliance on barrier()
>> causes the wrong code to be generated, but I can't help but be nervous
>> about it. It seems excessively fragile to me.
>> I wonder how many other places in the kernel are written the same way?
>
> Most of it. And since gcc 2.6 gcc has been basically right (2.5.8 didnt always
> get it right). We don't want to use volatile as that generates sucky code all
> over. Instead we prod the compiler into the right code in key places. The
> sti/cli and other locks also use these kind of things if you look to ensure
> temporaries are written back across interrupt locking
>
If you have an integer variable fun that at only a specific place you want
to use as a volatile, you can do:

while(*(volatile *)&fun);

This should only generate the sucky (and correct code) at that very place.

Ton
.