Refine some event code.
authorYang Rong <rong.r.yang@intel.com>
Thu, 3 Jul 2014 04:16:55 +0000 (12:16 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Thu, 3 Jul 2014 06:48:54 +0000 (14:48 +0800)
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 <rong.r.yang@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
src/cl_command_queue.c
src/cl_event.c

index 8426c4e..3184acb 100644 (file)
@@ -517,8 +517,12 @@ cl_command_queue_remove_event(cl_command_queue queue, cl_event event)
   if(i == queue->wait_events_num)
     return;
 
-  for(; i<queue->wait_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(; i<queue->wait_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(; i<queue->barrier_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(; i<queue->barrier_events_num-1; i++) {
+      queue->barrier_events[i] = queue->barrier_events[i+1];
+    }
   }
   queue->barrier_events_num -= 1;
 }
index a3af59c..1229820 100644 (file)
@@ -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; i<num_events_in_wait_list; i++) {
-    cb->wait_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; i<num_events_in_wait_list; i++) {
+    for(i=0; i<cb->num_events; i++) {
       if(cb->wait_list[i]) {
         cl_event_delete(cb->wait_list[i]);
       }