base: use atomic load/store in reference counting

Use the new atomic load and store macros for testing and setting reference
count overflow.
This commit is contained in:
Luke Howard
2020-07-13 10:04:18 +10:00
parent 4986ebcb67
commit bb7b4f7a94

View File

@@ -91,7 +91,7 @@ heim_retain(void *ptr)
if (ptr == NULL || heim_base_is_tagged(ptr))
return ptr;
if (p->ref_cnt == heim_base_atomic_integer_max)
if (heim_base_atomic_load(&p->ref_cnt) == heim_base_atomic_integer_max)
return ptr;
if ((heim_base_atomic_inc(&p->ref_cnt) - 1) == 0)
@@ -114,7 +114,7 @@ heim_release(void *ptr)
if (ptr == NULL || heim_base_is_tagged(ptr))
return;
if (p->ref_cnt == heim_base_atomic_integer_max)
if (heim_base_atomic_load(&p->ref_cnt) == heim_base_atomic_integer_max)
return;
old = heim_base_atomic_dec(&p->ref_cnt) + 1;
@@ -156,7 +156,7 @@ void
_heim_make_permanent(heim_object_t ptr)
{
struct heim_base *p = PTR2BASE(ptr);
p->ref_cnt = heim_base_atomic_integer_max;
heim_base_atomic_store(&p->ref_cnt, heim_base_atomic_integer_max);
}