From e5291eb0aab8f7a9c3d3bbd411062494d8099d3f Mon Sep 17 00:00:00 2001 From: Yang Rong Date: Thu, 3 Jul 2014 12:16:55 +0800 Subject: [PATCH] Refine some event code. 1. Do not add user event to cb->wait_list to avoid ref this user event twice. 2. Add assert when update status. 3. Set the queue's last wait event and barrier event to NULL when remove last event. Signed-off-by: Yang Rong Reviewed-by: Zhigang Gong --- src/cl_command_queue.c | 16 ++++++++++++---- src/cl_event.c | 11 +++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/cl_command_queue.c b/src/cl_command_queue.c index 8426c4e..3184acb 100644 --- a/src/cl_command_queue.c +++ b/src/cl_command_queue.c @@ -517,8 +517,12 @@ cl_command_queue_remove_event(cl_command_queue queue, cl_event event) if(i == queue->wait_events_num) return; - for(; iwait_events_num-1; i++) { - queue->wait_events[i] = queue->wait_events[i+1]; + if(i == queue->wait_events_num - 1) { + queue->wait_events[i] = NULL; + } else { + for(; iwait_events_num-1; i++) { + queue->wait_events[i] = queue->wait_events[i+1]; + } } queue->wait_events_num -= 1; } @@ -583,8 +587,12 @@ cl_command_queue_remove_barrier_event(cl_command_queue queue, cl_event event) if(i == queue->barrier_events_num) return; - for(; ibarrier_events_num-1; i++) { - queue->barrier_events[i] = queue->barrier_events[i+1]; + if(i == queue->barrier_events_num - 1) { + queue->barrier_events[i] = NULL; + } else { + for(; ibarrier_events_num-1; i++) { + queue->barrier_events[i] = queue->barrier_events[i+1]; + } } queue->barrier_events_num -= 1; } diff --git a/src/cl_event.c b/src/cl_event.c index a3af59c..1229820 100644 --- a/src/cl_event.c +++ b/src/cl_event.c @@ -261,11 +261,14 @@ void cl_event_new_enqueue_callback(cl_event event, /* Allocate and initialize the structure itself */ TRY_ALLOC_NO_ERR (cb, CALLOC(enqueue_callback)); - cb->num_events = num_events_in_wait_list; + cb->num_events = 0; TRY_ALLOC_NO_ERR (cb->wait_list, CALLOC_ARRAY(cl_event, num_events_in_wait_list)); for(i=0; iwait_list[i] = event_wait_list[i]; - cl_event_add_ref(event_wait_list[i]); //add defer enqueue's wait event reference + //user event will insert to cb->wait_user_events, need not in wait list, avoid ref twice + if(event_wait_list[i]->type != CL_COMMAND_USER) { + cb->wait_list[cb->num_events++] = event_wait_list[i]; + cl_event_add_ref(event_wait_list[i]); //add defer enqueue's wait event reference + } } cb->event = event; cb->next = NULL; @@ -360,7 +363,7 @@ error: cl_event_delete(u_ev->event); cl_free(u_ev); } - for(i=0; inum_events; i++) { if(cb->wait_list[i]) { cl_event_delete(cb->wait_list[i]); } -- 2.7.4