[sheepdog] [PATCH 1/2] add helper macros to try lock and unlock based on urcu

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Nov 1 06:59:32 CET 2012


At Thu, 01 Nov 2012 13:41:13 +0800,
Liu Yuan wrote:
> 
> On 11/01/2012 01:07 PM, MORITA Kazutaka wrote:
> > +/* return true if the lock was acquired */
> > +#define uatomic_trylock(lock)  (uatomic_cmpxchg((lock), 0, 1) == 0)
> > +#define uatomic_is_locked(lock)  (uatomic_read(lock) == 1)
> > +#define uatomic_unlock(lock) uatomic_set((lock), 0)
> > +
> 
> I think uatomic locker candy is useful for complex uatomic_cmpxchg()
> operation, but not so for true/false condition. How about add another
> candy for true/false condition like, uatomic_set_{true,false},
> uatomic_is_true candy helpers?

I guess lock/unlock semantics is more familiar with developers, but
either is fine to me.

But note that we can't use bool variables anyway for uatomic_*
functions because urcu complains the following warning.

  warning: cast from function call of type ‘long unsigned int’ to non-matching type ‘_B

Thanks,

Kazutaka



More information about the sheepdog mailing list