Skip to content

Commit a38af82

Browse files
committed
- Move the increase of the runInfo ref_count to inside the shallow copy function.
PR fixes.
1 parent 2fc477b commit a38af82

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/background_workers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void *RedisAI_Run_ThreadMain(void *arg) {
176176
if (timedOut == 1) {
177177
queueEvict(run_queue_info->run_queue, item);
178178

179-
long long dagRefCount = RAI_DagRunInfoDecreaseFetch(rinfo);
179+
long long dagRefCount = RAI_DagRunInfoFreeShallowCopy(rinfo);
180180
if (dagRefCount == 0 && rinfo->client) {
181181
RedisModule_UnblockClient(rinfo->client, rinfo);
182182
}
@@ -415,7 +415,7 @@ void *RedisAI_Run_ThreadMain(void *arg) {
415415
// If there was an error and the reference count for the dag
416416
// has gone to zero and the client is still around, we unblock
417417
if (dagError) {
418-
long long dagRefCount = RAI_DagRunInfoDecreaseFetch(rinfo);
418+
long long dagRefCount = RAI_DagRunInfoFreeShallowCopy(rinfo);
419419
if (dagRefCount == 0 && rinfo->client) {
420420
RedisModule_UnblockClient(rinfo->client, rinfo);
421421
}
@@ -438,7 +438,7 @@ void *RedisAI_Run_ThreadMain(void *arg) {
438438
if (device_complete == 1 || device_complete_after_run == 1) {
439439
RedisAI_RunInfo *evicted_rinfo = (RedisAI_RunInfo *)(evicted_items[0]->value);
440440
// We decrease and get the reference count for the DAG
441-
dagRefCount = RAI_DagRunInfoDecreaseFetch(evicted_rinfo);
441+
dagRefCount = RAI_DagRunInfoFreeShallowCopy(evicted_rinfo);
442442
}
443443

444444
// If the DAG was complete, then it's time to unblock the client

src/dag.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,6 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv, in
12301230
}
12311231

12321232
size_t ndevices = array_len(devices);
1233-
1234-
*rinfo->dagRefCount = ndevices;
1235-
12361233
RedisAI_RunInfo **rinfo_copies = array_new(RedisAI_RunInfo *, ndevices);
12371234
rinfo_copies = array_append(rinfo_copies, rinfo);
12381235

src/run_info.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ int RAI_InitRunInfo(RedisAI_RunInfo **result) {
123123
}
124124
rinfo->dagError = RedisModule_Calloc(1, sizeof(int));
125125
rinfo->dagLock = RedisModule_Alloc(sizeof(pthread_rwlock_t));
126-
rinfo->dagRefCount = RedisModule_Calloc(1, sizeof(long long));
126+
rinfo->dagRefCount = RedisModule_Alloc(sizeof(long long));
127+
*rinfo->dagRefCount = 1;
127128
rinfo->dagOpCount = 0;
128129
rinfo->dagCompleteOpCount = RedisModule_Calloc(1, sizeof(long long));
129130
rinfo->dagDeviceOpCount = 0;
@@ -145,6 +146,7 @@ int RAI_ShallowCopyDagRunInfo(RedisAI_RunInfo **result, RedisAI_RunInfo *src) {
145146
if (!(rinfo->dagDeviceOps)) {
146147
return REDISMODULE_ERR;
147148
}
149+
(*rinfo->dagRefCount)++;
148150
rinfo->dagDeviceOpCount = 0;
149151
rinfo->dagDeviceCompleteOpCount = 0;
150152
*result = rinfo;
@@ -197,7 +199,7 @@ void RAI_FreeDagOp(RedisModuleCtx *ctx, RAI_DagOp *dagOp) {
197199
}
198200
}
199201

200-
long long RAI_DagRunInfoDecreaseFetch(RedisAI_RunInfo *rinfo) {
202+
long long RAI_DagRunInfoFreeShallowCopy(RedisAI_RunInfo *rinfo) {
201203
long long ref_count = __atomic_sub_fetch(rinfo->dagRefCount, 1, __ATOMIC_RELAXED);
202204
RedisModule_Assert(ref_count >= 0);
203205
if (rinfo->dagDeviceOps) {
@@ -213,7 +215,7 @@ void RAI_FreeRunInfo(RedisModuleCtx *ctx, struct RedisAI_RunInfo *rinfo) {
213215
if (!rinfo) {
214216
return;
215217
}
216-
long long ref_count = __atomic_load_n(rinfo->dagRefCount, __ATOMIC_RELAXED);
218+
long long ref_count = *rinfo->dagRefCount;
217219
RedisModule_Assert(ref_count == 0);
218220
pthread_rwlock_destroy(rinfo->dagLock);
219221
RedisModule_Free(rinfo->dagLock);

src/run_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int RAI_ShallowCopyDagRunInfo(RedisAI_RunInfo **result, RedisAI_RunInfo *src);
108108
* @param rinfo copy to be freed.
109109
* @retval The ref_count of the rinfo object after freeing this copy.
110110
*/
111-
long long RAI_DagRunInfoDecreaseFetch(RedisAI_RunInfo *rinfo);
111+
long long RAI_DagRunInfoFreeShallowCopy(RedisAI_RunInfo *rinfo);
112112

113113
/**
114114
* Frees the memory allocated on RedisAI_RunInfo

0 commit comments

Comments
 (0)