diff options
author | Junyan He <junyan.he@intel.com> | 2016-04-26 16:38:12 +0800 |
---|---|---|
committer | Junyan He <junyan.he@intel.com> | 2016-04-26 16:38:12 +0800 |
commit | 3ffb2a8f4f9e8934c6b956a0e84f0b4bfb04580b (patch) | |
tree | cba988dd0e6cc6471e33f7fdc219dc34d495b55a | |
parent | ab96a06791a21afb1d3d37f71499272bd36a4021 (diff) |
add finish
-rw-r--r-- | libclapi/cl_command_queue.c | 28 | ||||
-rw-r--r-- | libclapi/cl_enqueue.c | 24 | ||||
-rw-r--r-- | libclapi/cl_internals.h | 1 |
3 files changed, 39 insertions, 14 deletions
diff --git a/libclapi/cl_command_queue.c b/libclapi/cl_command_queue.c index f0e7ecf2..4b1140ab 100644 --- a/libclapi/cl_command_queue.c +++ b/libclapi/cl_command_queue.c @@ -29,6 +29,20 @@ #include "cl_platform_id.h" #include "cl_device_id.h" +static cl_int cl_flush(cl_command_queue queue) +{ + cl_int err = CL_SUCCESS; + err = cl_enqueue_wait_for_flush(queue); + return err; +} + +static cl_int cl_finish(cl_command_queue queue) +{ + cl_int err = CL_SUCCESS; + err = cl_enqueue_wait_for_finish(queue); + return err; +} + static cl_command_queue cl_command_queue_new(cl_context ctx, cl_device_id device, cl_command_queue_properties properties) { @@ -142,20 +156,6 @@ LOCAL cl_int cl_retain_command_queue(cl_command_queue queue) return 0; } -static cl_int cl_flush(cl_command_queue queue) -{ - cl_int err = CL_SUCCESS; - err = cl_enqueue_wait_for_flush(queue); - return err; -} - -static cl_int cl_finish(cl_command_queue queue) -{ - cl_int err = CL_SUCCESS; - err = queue->device->driver->finish_command_queue(queue); - return err; -} - /************************************************************************************** ************************* CL APIs ******************************** **************************************************************************************/ diff --git a/libclapi/cl_enqueue.c b/libclapi/cl_enqueue.c index 3874b927..7457d86f 100644 --- a/libclapi/cl_enqueue.c +++ b/libclapi/cl_enqueue.c @@ -384,3 +384,27 @@ LOCAL cl_int cl_enqueue_wait_for_flush(cl_command_queue queue) return CL_SUCCESS; } +LOCAL cl_int cl_enqueue_wait_for_finish(cl_command_queue queue) +{ + cl_command_queue_worker worker = NULL; + + 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 (worker->quit == CL_FALSE) { + if (worker->work_items == NULL && worker->in_exec == CL_FALSE) + break; + + CL_COND_WAIT(&worker->cond, &worker->mutex); + } + + CL_MUTEX_UNLOCK(&worker->mutex); + return CL_SUCCESS; +} + diff --git a/libclapi/cl_internals.h b/libclapi/cl_internals.h index 70662f90..b8d40f0a 100644 --- a/libclapi/cl_internals.h +++ b/libclapi/cl_internals.h @@ -494,5 +494,6 @@ extern void cl_enqueue_destroy_work_item(cl_command_queue queue, cl_command_queu 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); #endif /* __CL_INTERNALS_H__ */ |