diff options
author | Junyan He <junyan.he@intel.com> | 2016-04-26 17:03:34 +0800 |
---|---|---|
committer | Junyan He <junyan.he@intel.com> | 2016-04-26 17:03:34 +0800 |
commit | 85a0b5eb1673168ee1fab2babc902c114b72e802 (patch) | |
tree | 5d02878fc072e0cebf37f8a60db3a180a8e5f69f | |
parent | aeeabe0a680e47f8f04484e0831c0b78e5a57cc7 (diff) |
add finish
-rw-r--r-- | libclapi/cl_enqueue.c | 77 | ||||
-rw-r--r-- | libclapi/cl_event.c | 2 | ||||
-rw-r--r-- | libclapi/cl_internals.h | 1 |
3 files changed, 69 insertions, 11 deletions
diff --git a/libclapi/cl_enqueue.c b/libclapi/cl_enqueue.c index 29344417..932d6866 100644 --- a/libclapi/cl_enqueue.c +++ b/libclapi/cl_enqueue.c @@ -352,16 +352,17 @@ LOCAL cl_int cl_enqueue_wait_for_flush(cl_command_queue queue) CL_MUTEX_LOCK(&worker->mutex); - if (worker->quit) { // already destroy the queue? - CL_MUTEX_UNLOCK(&worker->mutex); - return CL_INVALID_COMMAND_QUEUE; - } - while (worker->quit == CL_FALSE) { + while (1) { cl_bool need_to_wait = CL_FALSE; it = worker->work_items; start_it = it; + if (worker->quit) { // already destroy the queue? + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_INVALID_COMMAND_QUEUE; + } + while (it) { if (it->status > CL_SUBMITTED) {// Need not to lock, ready has been deleted from list need_to_wait = CL_TRUE; @@ -392,12 +393,13 @@ LOCAL cl_int cl_enqueue_wait_for_finish(cl_command_queue queue) worker = queue->worker; CL_MUTEX_LOCK(&worker->mutex); - if (worker->quit) { // already destroy the queue? - CL_MUTEX_UNLOCK(&worker->mutex); - return CL_INVALID_COMMAND_QUEUE; - } - while (worker->quit == CL_FALSE) { + while (1) { + if (worker->quit) { // already destroy the queue? + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_INVALID_COMMAND_QUEUE; + } + if (worker->work_items == NULL && worker->in_exec == CL_FALSE) break; @@ -426,3 +428,58 @@ LOCAL void cl_enqueue_notify_event_changed(cl_command_queue queue) CL_MUTEX_UNLOCK(&worker->mutex); } +LOCAL cl_int cl_enqueue_wait_for_events(cl_command_queue queue, const cl_event* events, int num) +{ + cl_command_queue_worker worker = NULL; + cl_bool need_to_wait = CL_FALSE; + cl_int status; + int i; + + assert(queue->worker != NULL); + worker = queue->worker; + + CL_MUTEX_LOCK(&worker->mutex); + + if (worker->quit) { // already destroy the queue? + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_INVALID_COMMAND_QUEUE; + } + + while (1) { + need_to_wait = CL_FALSE; + for (i = 0; i < num; i++) { + assert(events[i]); + assert(events[i]->queue == queue); + assert(!IS_MARKER_EVENT(events[i])); + assert(!IS_BARRIER_EVENT(events[i])); + + status = cl_event_get_status(events[i]); + if (status < CL_COMPLETE) { + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST; + } + + if (status > CL_COMPLETE) { + need_to_wait = CL_TRUE; + } + } + + if (need_to_wait) { + CL_COND_WAIT(&worker->cond, &worker->mutex); + } else { // All events are ready, OK now. + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_SUCCESS; + } + + if (worker->quit) { // already destroy the queue? + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_INVALID_COMMAND_QUEUE; + } + } + + // FAKE: Should never get here. + assert(0); + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_SUCCESS; +} + diff --git a/libclapi/cl_event.c b/libclapi/cl_event.c index 2af16f3e..c7a54552 100644 --- a/libclapi/cl_event.c +++ b/libclapi/cl_event.c @@ -129,7 +129,7 @@ LOCAL cl_int cl_event_set_status(cl_event event, cl_int status) for (i = 0; i < queue_num; i++) { if (queue_array[i]) { // We just ignore error. - queue_array[i]->device->driver->event_changed(event, queue_array[i], status); + cl_enqueue_notify_event_changed(queue_array[i]); } cl_release_command_queue(queue_array[i]); diff --git a/libclapi/cl_internals.h b/libclapi/cl_internals.h index b8d40f0a..f32bc65c 100644 --- a/libclapi/cl_internals.h +++ b/libclapi/cl_internals.h @@ -495,5 +495,6 @@ extern cl_int cl_command_queue_worker_init(cl_command_queue queue); extern void cl_command_queue_worker_destroy(cl_command_queue queue); extern cl_int cl_enqueue_wait_for_flush(cl_command_queue queue); extern cl_int cl_enqueue_wait_for_finish(cl_command_queue queue); +extern void cl_enqueue_notify_event_changed(cl_command_queue queue); #endif /* __CL_INTERNALS_H__ */ |