Messages in this thread | | | From | David Howells <> | Subject | Re: [PATCH] fix race in mark_mounts_for_expiry() | Date | Wed, 18 May 2005 11:46:15 +0100 |
| |
Miklos Szeredi <miklos@szeredi.hu> wrote:
> > How about using cmpxchg? > > How? If the count is nonzero, an incremented count must be stored. > You can't do that atomically with cmpxchg.
Yes you can. cmpxchg() is atomic. Several archs implement atomic_inc() and co with cmpxchg() or similar.
Something like:
static inline struct namespace *grab_namespace(struct namespace *n) { int old = atomic_read(&n->count);
while (old > 0) { /* attempt to increment the counter */ old = cmpxchg(&n->count, old, old + 1); }
return old > 0 ? n : NULL; }
David - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |