summaryrefslogtreecommitdiff
path: root/backend/src/driver/cl_gen_command_queue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/driver/cl_gen_command_queue.cpp')
-rw-r--r--backend/src/driver/cl_gen_command_queue.cpp79
1 files changed, 76 insertions, 3 deletions
diff --git a/backend/src/driver/cl_gen_command_queue.cpp b/backend/src/driver/cl_gen_command_queue.cpp
index 5ee7730e..1616487e 100644
--- a/backend/src/driver/cl_gen_command_queue.cpp
+++ b/backend/src/driver/cl_gen_command_queue.cpp
@@ -178,15 +178,63 @@ void GenGPUCommandQueue::waitOnEvent(GenGPUWorkItem* item)
}
while (this->quit == false) {
- if ((item && item->state == CL_COMPLETE) ||
- (!item && (this->workItems.empty() || this->inExec == true))) {
+ if (item && item->state != CL_COMPLETE) {
pthread_cond_wait(&this->cond, &this->mutex);
+ } else {
+ break;
}
}
pthread_mutex_unlock(&this->mutex);
}
+void GenGPUCommandQueue::waitForFlush(void)
+{
+ pthread_mutex_lock(&this->mutex);
+ if (this->quit) { // already destroy the queue?
+ pthread_mutex_unlock(&this->mutex);
+ return;
+ }
+
+ bool needWait = false;
+ while (this->quit == false) {
+ needWait = false;
+ for (list<GenGPUWorkItem*>::iterator it = this->workItems.begin();
+ it != this->workItems.end(); it++) {
+ if ((*it)->state > CL_SUBMITTED) {
+ needWait = true;
+ break;
+ }
+ }
+
+ if (needWait) {
+ pthread_cond_wait(&this->cond, &this->mutex);
+ } else {
+ break;
+ }
+ }
+
+ pthread_mutex_unlock(&this->mutex);
+}
+
+void GenGPUCommandQueue::waitForFinish(void)
+{
+ pthread_mutex_lock(&this->mutex);
+ if (this->quit) { // already destroy the queue?
+ pthread_mutex_unlock(&this->mutex);
+ return;
+ }
+
+ while (this->quit == false) {
+ if (this->workItems.empty() && this->inExec == false)
+ break;
+
+ pthread_cond_wait(&this->cond, &this->mutex);
+ }
+
+ pthread_mutex_unlock(&this->mutex);
+}
+
void GenGPUCommandQueue::userEventChange(void)
{
pthread_mutex_lock(&this->mutex);
@@ -263,10 +311,35 @@ cl_int GenReleaseCommandQueue(cl_command_queue queue)
{
GenGPUCommandQueue* gpuQueue = (GenGPUCommandQueue*)getGenCommandQueuePrivate(queue);
if (gpuQueue == NULL) {
- return CL_INVALID_VALUE;
+ return CL_INVALID_COMMAND_QUEUE;
}
GBE_DELETE(gpuQueue);
setGenCommandQueuePrivate(queue, NULL);
return CL_SUCCESS;
}
+
+extern "C"
+cl_int GenFlushCommandQueue(cl_command_queue queue)
+{
+ GenGPUCommandQueue* gpuQueue = (GenGPUCommandQueue*)getGenCommandQueuePrivate(queue);
+ if (gpuQueue == NULL) {
+ return CL_INVALID_COMMAND_QUEUE;
+ }
+
+ gpuQueue->waitForFlush();
+ return CL_SUCCESS;
+}
+
+extern "C"
+cl_int GenFinishCommandQueue(cl_command_queue queue)
+{
+ GenGPUCommandQueue* gpuQueue = (GenGPUCommandQueue*)getGenCommandQueuePrivate(queue);
+ if (gpuQueue == NULL) {
+ return CL_INVALID_COMMAND_QUEUE;
+ }
+
+ gpuQueue->waitForFinish();
+ return CL_SUCCESS;
+}
+