tbm_surface_queue: clean up tbm_surface_queue_can_dequeue / acquire 02/96302/1
authorYoungJun Cho <yj44.cho@samsung.com>
Tue, 8 Nov 2016 11:10:10 +0000 (20:10 +0900)
committerYoungJun Cho <yj44.cho@samsung.com>
Tue, 8 Nov 2016 11:10:10 +0000 (20:10 +0900)
This patch cleans up tbm_surface_queue_can_dequeue / acqurie
not to use 3-depth 'if' condition.

Change-Id: I7529ec36205eb25f1e772408686018b03a2baa18
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
src/tbm_surface_queue.c

index ec8b475bba0617a03de139d0a5d47540be3d910a..684bfd5cd18839e7583ecff7d9fda5a5d44ff64f 100644 (file)
@@ -1000,45 +1000,39 @@ tbm_surface_queue_can_dequeue(tbm_surface_queue_h surface_queue, int wait)
                        surface_queue->impl->need_attach(surface_queue);
 
                if (!_tbm_surface_queue_is_valid(surface_queue)) {
-                               TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
-                               _tbm_surf_queue_mutex_unlock();
-                               return 0;
+                       TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
+                       _tbm_surf_queue_mutex_unlock();
+                       return 0;
                }
        }
 
-       if (_queue_is_empty(&surface_queue->free_queue)) {
-               if (wait &&
-                       _tbm_surface_queue_get_node_count(surface_queue, QUEUE_NODE_TYPE_ACQUIRE)) {
-
-                       _tbm_surf_queue_mutex_unlock();
-
-                       pthread_cond_wait(&surface_queue->free_cond, &surface_queue->lock);
-
-                       _tbm_surf_queue_mutex_lock();
+       if (!_queue_is_empty(&surface_queue->free_queue)) {
+               pthread_mutex_unlock(&surface_queue->lock);
+               _tbm_surf_queue_mutex_unlock();
+               return 1;
+       }
 
-                       if (!_tbm_surface_queue_is_valid(surface_queue)) {
-                                 TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
-                                 _tbm_surf_queue_mutex_unlock();
-                                 return 0;
-                       }
+       if (wait && _tbm_surface_queue_get_node_count(surface_queue,
+                                               QUEUE_NODE_TYPE_ACQUIRE)) {
+               _tbm_surf_queue_mutex_unlock();
+               pthread_cond_wait(&surface_queue->free_cond, &surface_queue->lock);
+               _tbm_surf_queue_mutex_lock();
 
+               if (!_tbm_surface_queue_is_valid(surface_queue)) {
+                         TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
                        pthread_mutex_unlock(&surface_queue->lock);
-
-                       _tbm_surf_queue_mutex_unlock();
-                       return 1;
+                         _tbm_surf_queue_mutex_unlock();
+                         return 0;
                }
 
                pthread_mutex_unlock(&surface_queue->lock);
-
                _tbm_surf_queue_mutex_unlock();
-               return 0;
+               return 1;
        }
 
        pthread_mutex_unlock(&surface_queue->lock);
-
        _tbm_surf_queue_mutex_unlock();
-
-       return 1;
+       return 0;
 }
 
 tbm_surface_queue_error_e
@@ -1164,39 +1158,33 @@ tbm_surface_queue_can_acquire(tbm_surface_queue_h surface_queue, int wait)
 
        TBM_QUEUE_TRACE("tbm_surface_queue(%p)\n", surface_queue);
 
-       if (_queue_is_empty(&surface_queue->dirty_queue)) {
-               if (wait &&
-                       _tbm_surface_queue_get_node_count(surface_queue, QUEUE_NODE_TYPE_DEQUEUE)) {
-
-                       _tbm_surf_queue_mutex_unlock();
-
-                       pthread_cond_wait(&surface_queue->dirty_cond, &surface_queue->lock);
-
-                       _tbm_surf_queue_mutex_lock();
+       if (!_queue_is_empty(&surface_queue->dirty_queue)) {
+               pthread_mutex_unlock(&surface_queue->lock);
+               _tbm_surf_queue_mutex_unlock();
+               return 1;
+       }
 
-                       if (!_tbm_surface_queue_is_valid(surface_queue)) {
-                                 TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
-                                 _tbm_surf_queue_mutex_unlock();
-                                 return 0;
-                       }
+       if (wait && _tbm_surface_queue_get_node_count(surface_queue,
+                                               QUEUE_NODE_TYPE_DEQUEUE)) {
+               _tbm_surf_queue_mutex_unlock();
+               pthread_cond_wait(&surface_queue->dirty_cond, &surface_queue->lock);
+               _tbm_surf_queue_mutex_lock();
 
+               if (!_tbm_surface_queue_is_valid(surface_queue)) {
+                         TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
                        pthread_mutex_unlock(&surface_queue->lock);
-
-                       _tbm_surf_queue_mutex_unlock();
-                       return 1;
+                         _tbm_surf_queue_mutex_unlock();
+                         return 0;
                }
 
                pthread_mutex_unlock(&surface_queue->lock);
-
                _tbm_surf_queue_mutex_unlock();
-               return 0;
+               return 1;
        }
 
        pthread_mutex_unlock(&surface_queue->lock);
-
        _tbm_surf_queue_mutex_unlock();
-
-       return 1;
+       return 0;
 }
 
 void