Re: [PATCH] fix race in mark_mounts_for_expiry()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux