[Sheepdog] [PACH, RFC] sheep: use atomic for the vnode_info refcount outside the main thread

Christoph Hellwig hch at infradead.org
Mon May 7 18:21:13 CEST 2012


On Tue, May 08, 2012 at 12:04:09AM +0800, Yunkai Zhang wrote:
> > +static inline int atomic_read(atomic_t *v)
> > +{
> > + ? ? ? return *v;
> You can't directly read it! You should use __sync_xxx API to
> read/update in any time.
> 
> Use __sync_add_and_fetch(v, 0) to read it here.

I was surprised that gcc had not built-in for the read, as it needs
to cater to every imaginable architecture.  On anything remotely
sane 32-bit values are readable atomically - the only computers I know
of that run C where this is not posisble are really old Crays.

__sync_add_and_fetch sounds like and odd API, but I can't see how
it wouldn't work.  Let's hope gcc generates sane code for it.

> > +}
> > +
> > +static inline void atomic_inc(atomic_t *v)
> > +{
> > + ? ? ? __sync_add_and_fetch(v, 1);
> > +}
> I suggests use this form:
> static inline atomic_t *atomic_inc(atomic_t *v)
> {
>          return __sync_add_and_fetch(v, 1);
> }
> so that we can get the added result directly -- needn't to call
> atomic_read() again.

In Linux kernel terms that would be atomic_inc_return, but I can add it.



More information about the sheepdog mailing list