Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "backends.h"
#include "stats.h"
#include "backends/util.h"

#include <pthread.h>
#include "rmutil/alloc.h"
#include "util/arr_rm_alloc.h"
#include "util/dict.h"
Expand Down Expand Up @@ -298,7 +298,7 @@ RAI_Model *RAI_ModelCreate(RAI_Backend backend, const char* devicestr, const cha
}

void RAI_ModelFree(RAI_Model* model, RAI_Error* err) {
if (--model->refCount > 0){
if (__atomic_sub_fetch(&model->refCount, 1, __ATOMIC_RELAXED) > 0){
return;
}

Expand Down Expand Up @@ -466,7 +466,7 @@ int RAI_ModelRun(RAI_ModelRunCtx** mctxs, long long n, RAI_Error* err) {
}

RAI_Model* RAI_ModelGetShallowCopy(RAI_Model* model) {
++model->refCount;
__atomic_fetch_add(&model->refCount, 1, __ATOMIC_RELAXED);
return model;
}

Expand Down
5 changes: 3 additions & 2 deletions src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "script_struct.h"
#include "stats.h"
#include "util/arr_rm_alloc.h"
#include <pthread.h>

RedisModuleType* RedisAI_ScriptType = NULL;

Expand Down Expand Up @@ -126,7 +127,7 @@ RAI_Script* RAI_ScriptCreate(const char* devicestr, const char* tag,
}

void RAI_ScriptFree(RAI_Script* script, RAI_Error* err) {
if (--script->refCount > 0) {
if (__atomic_sub_fetch(&script->refCount, 1, __ATOMIC_RELAXED) > 0) {
return;
}

Expand Down Expand Up @@ -218,7 +219,7 @@ int RAI_ScriptRun(RAI_ScriptRunCtx* sctx, RAI_Error* err) {
}

RAI_Script* RAI_ScriptGetShallowCopy(RAI_Script* script) {
++script->refCount;
__atomic_fetch_add(&script->refCount, 1, __ATOMIC_RELAXED);
return script;
}

Expand Down
5 changes: 3 additions & 2 deletions src/tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "util/dict.h"
#include <assert.h>
#include "redisai.h"
#include <pthread.h>

RedisModuleType *RedisAI_TensorType = NULL;

Expand Down Expand Up @@ -480,7 +481,7 @@ size_t RAI_TensorDataSizeFromDLDataType(DLDataType dtype) {

void RAI_TensorFree(RAI_Tensor *t) {
if (t) {
if (--t->refCount <= 0) {
if (__atomic_sub_fetch(&t->refCount, 1, __ATOMIC_RELAXED) <= 0) {
if (t->tensor.deleter) {
t->tensor.deleter(&t->tensor);
} else {
Expand Down Expand Up @@ -632,7 +633,7 @@ int RAI_TensorGetValueAsLongLong(RAI_Tensor* t, long long i, long long* val) {
}

RAI_Tensor* RAI_TensorGetShallowCopy(RAI_Tensor* t){
++t->refCount;
__atomic_fetch_add(&t->refCount, 1, __ATOMIC_RELAXED);
return t;
}

Expand Down