Skip to content
Snippets Groups Projects
Commit 72d52395 authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Remove atomics from reference counting

Also fix the initial value. Fixes #1
parent 2ae3d561
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,6 @@
#include <errno.h>
#include <math.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -37,7 +36,7 @@ struct _Array
size_t capacity;
FreeFunc free_func;
atomic_int ref_count;
int ref_count;
};
static void
......@@ -92,6 +91,7 @@ array_new (FreeFunc func)
array->length = 0;
array->capacity = MIN_SIZE;
array->free_func = func;
array->ref_count = 1;
return array;
}
......@@ -107,7 +107,7 @@ array_new (FreeFunc func)
Array *
array_ref (Array *array)
{
atomic_fetch_add (&array->ref_count, 1);
array->ref_count++;
return array;
}
......@@ -122,7 +122,9 @@ array_ref (Array *array)
void
array_unref (Array *array)
{
if (atomic_fetch_sub (&array->ref_count, 1) == 1)
array->ref_count--;
if (array->ref_count == 0)
{
if (array->free_func)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment