Skip to content

Commit 55b48fe

Browse files
committed
Moved location of decoder destroy to prevent threading issues.
Moved the location of the cuvidDestroyDecoder call to the end of the resolve thread, to attempt to prevent multiple threads destroying it simultaneously.
1 parent ef84239 commit 55b48fe

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/vabackend.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,9 @@ static bool destroyContext(NVDriver *drv, NVContext *nvCtx) {
331331
freeBuffer(&nvCtx->sliceOffsets);
332332
freeBuffer(&nvCtx->bitstreamBuffer);
333333

334-
bool successful = true;
335-
if (nvCtx->decoder != NULL) {
336-
CUresult result = cv->cuvidDestroyDecoder(nvCtx->decoder);
337-
if (result != CUDA_SUCCESS) {
338-
LOG("cuvidDestroyDecoder failed: %d", result);
339-
successful = false;
340-
}
341-
}
342-
nvCtx->decoder = NULL;
343334
CHECK_CUDA_RESULT_RETURN(cu->cuCtxPopCurrent(NULL), false);
344335

345-
return successful;
336+
return true;
346337
}
347338

348339
static void deleteAllObjects(NVDriver *drv) {
@@ -455,6 +446,15 @@ static void* resolveSurfaces(void *param) {
455446
CHECK_CUDA_RESULT(cv->cuvidUnmapVideoFrame(ctx->decoder, deviceMemory));
456447
}
457448
out:
449+
//release the decoder here to prevent multiple threads attempting it
450+
if (ctx->decoder != NULL) {
451+
CUresult result = cv->cuvidDestroyDecoder(ctx->decoder);
452+
ctx->decoder = NULL;
453+
if (result != CUDA_SUCCESS) {
454+
LOG("cuvidDestroyDecoder failed: %d", result);
455+
}
456+
}
457+
458458
LOG("[RT] Resolve thread for %p exiting", ctx);
459459
return NULL;
460460
}

src/vabackend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ typedef struct _NVContext
176176
NVSurface* surfaceQueue[SURFACE_QUEUE_SIZE];
177177
int surfaceQueueReadIdx;
178178
int surfaceQueueWriteIdx;
179-
bool exiting;
179+
volatile bool exiting;
180180
pthread_mutex_t surfaceCreationMutex;
181181
int surfaceCount;
182182
} NVContext;

0 commit comments

Comments
 (0)