urcu_ref: do error checking on urcu_ref_put
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 9 Jun 2011 14:15:28 +0000 (10:15 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 9 Jun 2011 14:15:28 +0000 (10:15 -0400)
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 <pbonzini@redhat.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu/urcu_ref.h

index bce711619a8b77dfb5795e5aee8421964d6028ac..75620d14f576b30f38bcc4836d4c2b7e88a56594 100644 (file)
@@ -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);
 }
 
This page took 0.024807 seconds and 4 git commands to generate.