- 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;
+ }
* zero. Returns true if the reference is taken, false otherwise. This
* needs to be used in conjunction with another synchronization
* technique (e.g. RCU or mutex) to ensure existence of the reference
* zero. Returns true if the reference is taken, false otherwise. This
* needs to be used in conjunction with another synchronization
* technique (e.g. RCU or mutex) to ensure existence of the reference
return false; /* Failure. */
_new = old + 1;
res = uatomic_cmpxchg(&ref->refcount, old, _new);
return false; /* Failure. */
_new = old + 1;
res = uatomic_cmpxchg(&ref->refcount, old, _new);