From bf27322dfd077203b5f8a58548560158dccd8c60 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 9 Jun 2011 10:15:28 -0400 Subject: [PATCH] urcu_ref: do error checking on urcu_ref_put Underflow is what you really want to trap. When you reach urcu_ref_get, it is already too late. [Edit: whitespaces -> tab cleanup] Signed-off-by: Paolo Bonzini Signed-off-by: Mathieu Desnoyers --- urcu/urcu_ref.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/urcu/urcu_ref.h b/urcu/urcu_ref.h index bce7116..75620d1 100644 --- a/urcu/urcu_ref.h +++ b/urcu/urcu_ref.h @@ -33,14 +33,15 @@ static inline void urcu_ref_init(struct urcu_ref *ref) static inline void urcu_ref_get(struct urcu_ref *ref) { - long res = uatomic_add_return(&ref->refcount, 1); - assert(res != 0); + uatomic_add(&ref->refcount, 1); } static inline void urcu_ref_put(struct urcu_ref *ref, void (*release)(struct urcu_ref *)) { - if (!uatomic_sub_return(&ref->refcount, 1)) + long res = uatomic_sub_return(&ref->refcount, 1); + assert (res >= 0); + if (res == 0) release(ref); } -- 2.34.1