Skip to content

Commit a6853b8

Browse files
committed
event: unlock notifier when releasing wait event
Since clReleaseEvent may call clReleaseCommandQueue, the notifier event needs to be also unlocked to prevent lock order violations.
1 parent 0b9e368 commit a6853b8

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

lib/CL/devices/common.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -848,13 +848,6 @@ pocl_broadcast (cl_event brc_event)
848848
while ((target = brc_event->notify_list))
849849
{
850850
POCL_LOCK_OBJ (target->event);
851-
if (target != brc_event->notify_list)
852-
{
853-
assert (0 && "should be unreachable");
854-
pocl_unlock_events_inorder (brc_event, target->event);
855-
POCL_LOCK_OBJ (brc_event);
856-
continue;
857-
}
858851

859852
/* remove event from wait list */
860853
LL_FOREACH (target->event->wait_list, tmp)
@@ -867,29 +860,35 @@ pocl_broadcast (cl_event brc_event)
867860
}
868861
}
869862

870-
if ((target->event->status == CL_SUBMITTED)
871-
|| (target->event->status == CL_QUEUED))
872-
{
873-
target->event->command->device->ops->notify (
874-
target->event->command->device, target->event, brc_event);
875-
}
863+
if ((target->event->status == CL_SUBMITTED)
864+
|| (target->event->status == CL_QUEUED))
865+
{
866+
target->event->command->device->ops->notify (
867+
target->event->command->device, target->event, brc_event);
868+
}
876869

877-
if (pocl_is_tracing_enabled() && target->event->meta_data)
878-
{
879-
pocl_event_md *md = target->event->meta_data;
880-
for (size_t i = 0; i < md->num_deps; ++i)
881-
if (md->dep_ids[i] == brc_event->id)
882-
{
883-
md->dep_ts[i] = brc_event->time_end;
884-
break;
885-
}
886-
}
887-
LL_DELETE (brc_event->notify_list, target);
888-
POCL_UNLOCK_OBJ (target->event);
889-
/* Now that the event is deleted from the notify_list,
890-
* undo the retain done during pocl_create_event_sync. */
891-
POname (clReleaseEvent) (target->event);
892-
pocl_mem_manager_free_event_node (target);
870+
if (pocl_is_tracing_enabled () && target->event->meta_data)
871+
{
872+
pocl_event_md *md = target->event->meta_data;
873+
for (size_t i = 0; i < md->num_deps; ++i)
874+
if (md->dep_ids[i] == brc_event->id)
875+
{
876+
md->dep_ts[i] = brc_event->time_end;
877+
break;
878+
}
879+
}
880+
LL_DELETE (brc_event->notify_list, target);
881+
POCL_UNLOCK_OBJ (target->event);
882+
/* Unlock and lock brc_event to prevent lock order violations with the
883+
* command queue when calling clReleaseEvent as it can call
884+
* clReleaseCommandQueue.
885+
*/
886+
POCL_UNLOCK_OBJ (brc_event);
887+
/* Now that the event is deleted from the notify_list,
888+
* undo the retain done during pocl_create_event_sync. */
889+
POname (clReleaseEvent) (target->event);
890+
POCL_LOCK_OBJ (brc_event);
891+
pocl_mem_manager_free_event_node (target);
893892
}
894893
POCL_UNLOCK_OBJ (brc_event);
895894
}

0 commit comments

Comments
 (0)