Skip to content

Commit 8feee57

Browse files
committed
Delete allocations outside of lock
1 parent 65ff110 commit 8feee57

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

offload/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,19 +1337,23 @@ Error PinnedAllocationMapTy::unlockUnmappedHostBuffer(void *HstPtr) {
13371337

13381338
Error GenericDeviceTy::synchronize(__tgt_async_info *AsyncInfo,
13391339
bool RemoveQueue) {
1340-
std::lock_guard<std::mutex> AllocationGuard{AsyncInfo->Mutex};
1340+
SmallVector<void *, 2> AllocsToDelete{};
1341+
{
1342+
std::lock_guard<std::mutex> AllocationGuard{AsyncInfo->Mutex};
13411343

1342-
if (!AsyncInfo || !AsyncInfo->Queue)
1343-
return Plugin::error(ErrorCode::INVALID_ARGUMENT,
1344-
"invalid async info queue");
1344+
if (!AsyncInfo || !AsyncInfo->Queue)
1345+
return Plugin::error(ErrorCode::INVALID_ARGUMENT,
1346+
"invalid async info queue");
13451347

1346-
if (auto Err = synchronizeImpl(*AsyncInfo, RemoveQueue))
1347-
return Err;
1348+
if (auto Err = synchronizeImpl(*AsyncInfo, RemoveQueue))
1349+
return Err;
1350+
1351+
std::swap(AllocsToDelete, AsyncInfo->AssociatedAllocations);
1352+
}
13481353

1349-
for (auto *Ptr : AsyncInfo->AssociatedAllocations)
1354+
for (auto *Ptr : AllocsToDelete)
13501355
if (auto Err = dataDelete(Ptr, TargetAllocTy::TARGET_ALLOC_DEVICE))
13511356
return Err;
1352-
AsyncInfo->AssociatedAllocations.clear();
13531357

13541358
return Plugin::success();
13551359
}

0 commit comments

Comments
 (0)