@@ -3227,19 +3227,28 @@ pi_result piQueueFinish(pi_queue Queue) {
3227
3227
// Wait until command lists attached to the command queue are executed.
3228
3228
PI_ASSERT (Queue, PI_INVALID_QUEUE);
3229
3229
3230
- // Lock automatically releases when this goes out of scope.
3231
- std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
3230
+ std::vector<ze_command_queue_handle_t > ZeQueues;
3231
+ {
3232
+ // Lock automatically releases when this goes out of scope.
3233
+ std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
3232
3234
3233
- // execute any command list that may still be open.
3234
- if (auto Res = Queue->executeAllOpenCommandLists ())
3235
- return Res;
3235
+ // execute any command list that may still be open.
3236
+ if (auto Res = Queue->executeAllOpenCommandLists ())
3237
+ return Res;
3236
3238
3237
- ZE_CALL (zeHostSynchronize, (Queue->ZeComputeCommandQueue ));
3238
- for (uint32_t i = 0 ; i < Queue->ZeCopyCommandQueues .size (); ++i) {
3239
- if (Queue->ZeCopyCommandQueues [i])
3240
- ZE_CALL (zeHostSynchronize, (Queue->ZeCopyCommandQueues [i]));
3239
+ ZeQueues = Queue->ZeCopyCommandQueues ;
3240
+ ZeQueues.push_back (Queue->ZeComputeCommandQueue );
3241
3241
}
3242
3242
3243
+ // Don't hold a lock to the queue's mutex while waiting.
3244
+ // This allows continue working with the queue from other threads.
3245
+ for (auto ZeQueue : ZeQueues) {
3246
+ if (ZeQueue)
3247
+ ZE_CALL (zeHostSynchronize, (ZeQueue));
3248
+ }
3249
+
3250
+ // Lock automatically releases when this goes out of scope.
3251
+ std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
3243
3252
// Prevent unneeded already finished events to show up in the wait list.
3244
3253
Queue->LastCommandEvent = nullptr ;
3245
3254
0 commit comments