summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2022-02-09 17:25:28 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2022-02-09 17:25:28 +0000
commit60a9104f6b737976e30271ac1c1a432cd9a5c657 (patch)
treed1d0617cf189e04ff41d979d6adf13717c7c055a /memory.c
parent36e45dfccb5e5321682c0ec24dead22cf40fcb16 (diff)
Encode ref count in bit mask too
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/memory.c b/memory.c
index 8bca068..f1ff3a3 100644
--- a/memory.c
+++ b/memory.c
@@ -57,13 +57,13 @@ freearray(Array *a)
{
if(a == nil)
return;
- if(a->refs == 0){
+ if(GetRefs(a) == 0){
print("NEGATIVE REF COUNT (array)! %p\n", a);
threadexitsall(nil);
}
- a->refs--;
- if(a->refs == 0){
+ SetRefs(a, GetRefs(a)-1);
+ if(GetRefs(a) == 0){
if(GetType(a) == AtypeArray)
for(int i = 0; i < GetSize(a); i++)
freearray(a->arraydata[i]);
@@ -82,9 +82,9 @@ allocarray(arrayDataType t, int rank, int size)
SetType(a, t);
SetSize(a, size);
SetStrand(a, 0);
+ SetRefs(a, 1);
a->shape = emalloc(sizeof(*a->shape) * rank);
a->rawdata = emalloc(datasizes[t] * size);
- a->refs = 1;
arrayalloccounts++;
return a;
}
@@ -92,7 +92,7 @@ allocarray(arrayDataType t, int rank, int size)
void
incarrayref(Array *a)
{
- a->refs++;
+ SetRefs(a, GetRefs(a)+1);
}
Datum *