[Beignet] [PATCH] Fix: Event callback that not executed when command already marked CL_COMPLETE

David Couturier david.couturier at polymtl.ca
Thu Mar 19 17:19:49 PDT 2015


When trying to register a callback on the clEnqueueReadBuffer command, 
since it is processed
synchroniously all the time, the command was marked CL_COMPLETE every 
time. If the event returned
by clEnqueueReadBuffer was then used to register a callback function, 
the callback function did
no check to execute it if nessary.

Fixed by adding a check at the end of the cl_event_set_callback function.

All tests passed.

Signed-off-by: David Couturier <david.couturier at polymtl.ca>
---
  src/cl_event.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)

diff --git a/src/cl_event.c b/src/cl_event.c
index f70e531..df4a5a5 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -183,6 +183,21 @@ cl_int cl_event_set_callback(cl_event event ,
    cb->next        = event->user_cb;
    event->user_cb  = cb;

+  // It is possible that the event enqueued is already completed.
+  // clEnqueueReadBuffer can be synchronious and when the callback
+  // is registered after, it still needs to get executed.
+  if(event->status == CL_COMPLETE) {
+         /* Call user callback */
+         user_callback *user_cb = event->user_cb;
+         while(user_cb) {
+                 if(user_cb->status >= CL_COMPLETE) {
+                         user_cb->executed = CL_TRUE;
+                         user_cb->pfn_notify(event, event->status, 
user_cb->user_data);
+                 }
+                 user_cb = user_cb->next;
+         }
+  }
+
  exit:
    return err;
  error:
-- 
1.9.1


More information about the Beignet mailing list