> 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; > } > Ahh OK :) There's still the problem of cmpxchg meddling in the internals of an atomic_t. Is that OK? Will that work on all archs? Miklos - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [PATCH] fix race in mark_mounts_for_expiry()
- From: Trond Myklebust <[email protected]>
- Re: [PATCH] fix race in mark_mounts_for_expiry()
- References:
- Re: [PATCH] fix race in mark_mounts_for_expiry()
- From: Miklos Szeredi <[email protected]>
- [PATCH] fix race in mark_mounts_for_expiry()
- From: Miklos Szeredi <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Ram <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Miklos Szeredi <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Miklos Szeredi <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Ram <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Jamie Lokier <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Ram <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Miklos Szeredi <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Jamie Lokier <[email protected]>
- Re: [PATCH] namespace.c: fix bind mount from foreign namespace
- From: Miklos Szeredi <[email protected]>
- Re: [PATCH] fix race in mark_mounts_for_expiry()
- From: David Howells <[email protected]>
- Re: [PATCH] fix race in mark_mounts_for_expiry()
- From: David Howells <[email protected]>
- Re: [PATCH] fix race in mark_mounts_for_expiry()
- Prev by Date: Re: Illegal use of reserved word in system.h
- Next by Date: Re: Broken scsi on 2.6.12rc4 + realtime-preempt-2.6.12-rc4-V0.7.47-03 ( adaptec aic7901a and lsi 53c1030 fusion-mpt )
- Previous by thread: Re: [PATCH] fix race in mark_mounts_for_expiry()
- Next by thread: Re: [PATCH] fix race in mark_mounts_for_expiry()
- Index(es):