On 09/13/2012 09:54 AM, liu ping fan wrote: >>> +typedef struct Atomic { >>> + int counter; >>> +} Atomic; >> >> Best to mark counter 'volatile'. >> >>> + >>> +static inline void atomic_set(Atomic *v, int i) >>> +{ >>> + v->counter = i; >>> +} >>> + >>> +static inline int atomic_read(Atomic *v) >>> +{ >>> + return v->counter; >>> +} >>> >> >> So these two operations don't get mangled by the optimizer. >> > Browsing linux code and reading lkml, find some similar material. But > they have moved volatile from ->counter to function - atomic_read(). > As to atomic_read(), I think it need to prevent optimizer from > refetching issue, but as to atomic_set(), do we need ?
I think so, to prevent reordering. -- error compiling committee.c: too many arguments to function