[Beignet] [PATCH] Refine some event code.

Yang Rong rong.r.yang at intel.com
Wed Jul 2 21:16:55 PDT 2014


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 at intel.com>
---
 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(; 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;
 }
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; 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]);
       }
-- 
1.8.3.2



More information about the Beignet mailing list