On Thu, 2007-08-09 at 08:40 -0400, Chris Snook wrote: > > #define reload_var(x) __asm__ __volatile__ (whatever, x) > > > > I don't know inline assembly that much, but isn't it possible > > with that to kind of "fake-touch" the variable, so the compiler > > must reload it (and only it) to make sure it's up to date? > > We can do it in C, like this: > > -#define atomic_read(v) ((v)->counter) > +#define atomic_read(v) (*(volatile int *)&(v)->counter) > > By casting it volatile at the precise piece of code where we want to > guarantee a read from memory, there's little risk of the compiler > getting creative in its interpretation of the code.
To answer the inline assembler question: asm volatile ("" : "=m" (counter)) : "m" (counter) ) will force the compiler to reload the value from memory. But the cast to (volatile int *) is even better. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin. - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html