[Sheepdog] [PATCH] zookeeper: switch gcc atomic builtins to atomic helpers

Christoph Hellwig hch at infradead.org
Tue May 8 16:41:01 CEST 2012


On Tue, May 08, 2012 at 08:40:34PM +0800, Yunkai Zhang wrote:
> > ? ? ? ?if (!uatomic_read(&zk_notify_blocked) &&
> > ? ? ? ? ? ? uatomic_read(&nr_zk_levents)) {
> > ? ? ? ? ? ? ? ?nr_levents = uatomic_sub_return(&nr_zk_levents, 1) + 1;
> >
> > I guess he means the possible race between uatomic_read() and
> > uatomic_sub_return() on the same value.
> 
> I have explained - when we are trying to subtract nr_zk_levents, it
> will be added by watcher() in another thread.

I still don't really understand the problem.  If we need this to be
atomic (and I think we do) we'd need something like
atomic_dec_if_positive in the Linux Kernel - unfortunately urcu does not
seem to provide an equivalent.

Normally you'd use a proper lock for this sort of concurrency issue,
if you need something lockless you'd want a relatively complicated
producer/consumer queue like the one in include/linux/llist.h in the
Linux Kernel.



More information about the sheepdog mailing list