Re: [PATCH 1/2] kref: add kref_test_and_get

From: Eric Dumazet
Date: Tue Jan 04 2011 - 11:05:25 EST


Le mardi 04 janvier 2011 Ã 16:52 +0100, Jerome Marchand a Ãcrit :
> Add kref_test_and_get() function, which atomically add a reference only if
> refcount is not zero. This prevent to add a reference to an object that is
> already being removed.
>
> Signed-off-by: Jerome Marchand <jmarchan@xxxxxxxxxx>

> +int kref_test_and_get(struct kref *kref)
> +{
> + int ret;
> + smp_mb__before_atomic_inc();
> + ret = atomic_inc_not_zero(&kref->refcount);
> + smp_mb__after_atomic_inc();
> + return ret;
> +}
> +
> +/**

atomic_inc_not_zero() has full memory barrier semantic already, you dont
need smp_mb__before_atomic_inc() or smp_mb__after_atomic_inc();



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/