@@ -221,9 +221,8 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
221221 return UR_RESULT_SUCCESS;
222222 }
223223
224- ur_event_handle_t InternalEvent ;
224+ ur_event_handle_t ResultEvent = nullptr ;
225225 bool IsInternal = OutEvent == nullptr ;
226- ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent;
227226
228227 // For in-order queue and wait-list which is empty or has events from
229228 // the same queue just use the last command event as the barrier event.
@@ -234,7 +233,10 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
234233 EventWaitList) &&
235234 Queue->LastCommandEvent && !Queue->LastCommandEvent ->IsDiscarded ) {
236235 UR_CALL (ur::level_zero::urEventRetain (Queue->LastCommandEvent ));
237- *Event = Queue->LastCommandEvent ;
236+ ResultEvent = Queue->LastCommandEvent ;
237+ if (OutEvent) {
238+ *OutEvent = ResultEvent;
239+ }
238240 return UR_RESULT_SUCCESS;
239241 }
240242
@@ -264,16 +266,21 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
264266 EventWaitList, OkToBatch));
265267
266268 // Insert the barrier into the command-list and execute.
267- UR_CALL (insertBarrierIntoCmdList (CmdList, TmpWaitList, *Event, IsInternal));
269+ UR_CALL (insertBarrierIntoCmdList (CmdList, TmpWaitList, ResultEvent,
270+ IsInternal));
268271
269272 UR_CALL (Queue->executeCommandList (CmdList, false , OkToBatch));
270273
271274 // Because of the dependency between commands in the in-order queue we don't
272275 // need to keep track of any active barriers if we have in-order queue.
273276 if (UseMultipleCmdlistBarriers && !Queue->isInOrderQueue ()) {
274- auto UREvent = reinterpret_cast <ur_event_handle_t >(*Event );
277+ auto UREvent = reinterpret_cast <ur_event_handle_t >(ResultEvent );
275278 Queue->ActiveBarriers .add (UREvent);
276279 }
280+
281+ if (OutEvent) {
282+ *OutEvent = ResultEvent;
283+ }
277284 return UR_RESULT_SUCCESS;
278285 }
279286
@@ -361,14 +368,14 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
361368 // Insert a barrier with the events from each command-queue into the
362369 // convergence command list. The resulting event signals the convergence of
363370 // all barriers.
364- UR_CALL (insertBarrierIntoCmdList (ConvergenceCmdList, BaseWaitList, *Event,
365- IsInternal));
371+ UR_CALL (insertBarrierIntoCmdList (ConvergenceCmdList, BaseWaitList,
372+ ResultEvent, IsInternal));
366373 } else {
367374 // If there is only a single queue then insert a barrier and the single
368375 // result event can be used as our active barrier and used as the return
369376 // event. Take into account whether output event is discarded or not.
370- UR_CALL (insertBarrierIntoCmdList (CmdLists[0 ], _ur_ze_event_list_t {}, *Event,
371- IsInternal));
377+ UR_CALL (insertBarrierIntoCmdList (CmdLists[0 ], _ur_ze_event_list_t {},
378+ ResultEvent, IsInternal));
372379 }
373380
374381 // Execute each command list so the barriers can be encountered.
@@ -384,8 +391,10 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
384391 }
385392
386393 UR_CALL (Queue->ActiveBarriers .clear ());
387- auto UREvent = reinterpret_cast <ur_event_handle_t >(*Event);
388- Queue->ActiveBarriers .add (UREvent);
394+ Queue->ActiveBarriers .add (ResultEvent);
395+ if (OutEvent) {
396+ *OutEvent = ResultEvent;
397+ }
389398 return UR_RESULT_SUCCESS;
390399}
391400
0 commit comments