tbm_surface_queue: attach and check surface when free_cond is awakened 48/209748/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Mon, 8 Jul 2019 03:09:50 +0000 (12:09 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Mon, 8 Jul 2019 03:10:43 +0000 (12:10 +0900)
Change-Id: I2a2f3efa19c91ec8bc610766cd8aae5d24f6de38

src/tbm_surface_queue.c

index 7570280..06ddc5d 100644 (file)
@@ -1403,8 +1403,15 @@ tbm_surface_queue_can_dequeue_wait_timeout(tbm_surface_queue_h surface_queue, in
                                TBM_INFO("surface_queue:%p timedwait error retry wait", surface_queue);
                        }
                } else {
-                       pthread_mutex_unlock(&surface_queue->lock);
-                       return TBM_SURFACE_QUEUE_ERROR_NONE;
+                       if (surface_queue->impl && surface_queue->impl->need_attach)
+                               surface_queue->impl->need_attach(surface_queue);
+                       else
+                               _tbm_surface_queue_need_attach(surface_queue);
+
+                       if (!_queue_is_empty(&surface_queue->free_queue)) {
+                               pthread_mutex_unlock(&surface_queue->lock);
+                               return TBM_SURFACE_QUEUE_ERROR_NONE;
+                       }
                }
        }
 }
@@ -1444,9 +1451,19 @@ tbm_surface_queue_can_dequeue(tbm_surface_queue_h surface_queue, int wait)
 
        if (wait) {
                _tbm_surf_queue_mutex_unlock();
-               pthread_cond_wait(&surface_queue->free_cond, &surface_queue->lock);
-               pthread_mutex_unlock(&surface_queue->lock);
-               return 1;
+               while (1) {
+                       pthread_cond_wait(&surface_queue->free_cond, &surface_queue->lock);
+
+                       if (surface_queue->impl && surface_queue->impl->need_attach)
+                               surface_queue->impl->need_attach(surface_queue);
+                       else
+                               _tbm_surface_queue_need_attach(surface_queue);
+
+                       if (!_queue_is_empty(&surface_queue->free_queue)) {
+                               pthread_mutex_unlock(&surface_queue->lock);
+                               return 1;
+                       }
+               }
        }
 
        pthread_mutex_unlock(&surface_queue->lock);