Skip to content

Commit

Permalink
refcount check the old value before acquire as well (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK authored Mar 10, 2022
1 parent 3026862 commit 7df88ac
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/ref_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ void aws_ref_count_init(struct aws_ref_count *ref_count, void *object, aws_simpl
}

void *aws_ref_count_acquire(struct aws_ref_count *ref_count) {
aws_atomic_fetch_add(&ref_count->ref_count, 1);
size_t old_value = aws_atomic_fetch_add(&ref_count->ref_count, 1);
AWS_ASSERT(old_value > 0 && "refcount has been zero, it's invalid to use it again.");
(void)old_value;

return ref_count->object;
}
Expand Down

0 comments on commit 7df88ac

Please sign in to comment.