X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=urcu%2Fref.h;h=f2de26a7b0f1b81fbcce6ad6165c1fbe3f8f34aa;hb=3a03e6f37ee999c96024b8b99ba875a688fa1fe9;hp=a422a9906fd787d1482210a5a61b6f3611b7f99c;hpb=e9529b91ce756b476f5ad339512482c93c03c046;p=urcu.git diff --git a/urcu/ref.h b/urcu/ref.h index a422a99..f2de26a 100644 --- a/urcu/ref.h +++ b/urcu/ref.h @@ -15,6 +15,8 @@ */ #include +#include +#include #include struct urcu_ref { @@ -33,7 +35,20 @@ static inline void urcu_ref_init(struct urcu_ref *ref) static inline void urcu_ref_get(struct urcu_ref *ref) { - uatomic_add(&ref->refcount, 1); + long old, _new, res; + + old = uatomic_read(&ref->refcount); + for (;;) { + if (old == LONG_MAX) { + abort(); + } + _new = old + 1; + res = uatomic_cmpxchg(&ref->refcount, old, _new); + if (res == old) { + return; + } + old = res; + } } static inline void urcu_ref_put(struct urcu_ref *ref,