tbm_surface_queue: Don't wait enqueue if queue deosn't have dequeue type node 31/80931/2 accepted/tizen/common/20160721.180438 accepted/tizen/ivi/20160721.092916 accepted/tizen/mobile/20160721.092351 accepted/tizen/tv/20160721.091639 accepted/tizen/wearable/20160721.091950 submit/tizen/20160721.043111
authorChangyeon Lee <cyeon.lee@samsung.com>
Thu, 21 Jul 2016 01:59:19 +0000 (10:59 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 21 Jul 2016 04:04:44 +0000 (21:04 -0700)
Change-Id: Ib8621a33221253c4f952124f7abd225bd96cfba6

src/tbm_surface_queue.c

index 16eeb85..9648a9a 100644 (file)
@@ -52,6 +52,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define TBM_UNLOCK()
 #endif
 
+typedef enum _queue_node_type {
+       QUEUE_NODE_TYPE_NONE,
+       QUEUE_NODE_TYPE_DEQUEUE,
+       QUEUE_NODE_TYPE_ENQUEUE,
+       QUEUE_NODE_TYPE_ACQUIRE,
+       QUEUE_NODE_TYPE_RELEASE
+} Queue_Node_Type;
+
 typedef struct {
        struct list_head head;
        int count;
@@ -63,6 +71,8 @@ typedef struct {
        struct list_head item_link;
        struct list_head link;
 
+       Queue_Node_Type type;
+
        unsigned int priv_flags;        /*for each queue*/
 } queue_node;
 
@@ -177,6 +187,20 @@ _queue_node_pop(queue *queue, queue_node *node)
        return node;
 }
 
+static int
+_queue_has_node_type(tbm_surface_queue_h surface_queue, Queue_Node_Type type)
+{
+       queue_node *node = NULL;
+       queue_node *tmp = NULL;
+
+       LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->list, link) {
+               if (node->type == type)
+                       return 1;
+       }
+
+       return 0;
+}
+
 static queue_node *
 _queue_get_node(tbm_surface_queue_h surface_queue, int type,
                tbm_surface_h surface, int *out_type)
@@ -672,6 +696,8 @@ tbm_surface_queue_enqueue(tbm_surface_queue_h
                return TBM_SURFACE_QUEUE_ERROR_NONE;
        }
 
+       node->type = QUEUE_NODE_TYPE_ENQUEUE;
+
        pthread_mutex_unlock(&surface_queue->lock);
        pthread_cond_signal(&surface_queue->dirty_cond);
 
@@ -711,6 +737,7 @@ tbm_surface_queue_dequeue(tbm_surface_queue_h
                return TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
        }
 
+       node->type = QUEUE_NODE_TYPE_DEQUEUE;
        *surface = node->surface;
 
        TBM_QUEUE_TRACE("tbm_surface_queue(%p) tbm_surface(%p)\n", surface_queue, *surface);
@@ -784,6 +811,8 @@ tbm_surface_queue_release(tbm_surface_queue_h
                return TBM_SURFACE_QUEUE_ERROR_NONE;
        }
 
+       node->type = QUEUE_NODE_TYPE_RELEASE;
+
        pthread_mutex_unlock(&surface_queue->lock);
        pthread_cond_signal(&surface_queue->free_cond);
 
@@ -823,6 +852,8 @@ tbm_surface_queue_acquire(tbm_surface_queue_h
                return TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
        }
 
+       node->type = QUEUE_NODE_TYPE_ACQUIRE;
+
        *surface = node->surface;
 
        TBM_QUEUE_TRACE("tbm_surface_queue(%p) tbm_surface(%p)\n", surface_queue, *surface);
@@ -843,6 +874,12 @@ tbm_surface_queue_can_acquire(tbm_surface_queue_h surface_queue, int wait)
 
        if (_queue_is_empty(&surface_queue->dirty_queue)) {
                if (wait) {
+                       if (!_queue_has_node_type(surface_queue, QUEUE_NODE_TYPE_DEQUEUE)) {
+                               TBM_LOG_E("Deosn't have dequeue type node\n");
+                               pthread_mutex_unlock(&surface_queue->lock);
+                               return 0;
+                       }
+
                        pthread_cond_wait(&surface_queue->dirty_cond, &surface_queue->lock);
                        pthread_mutex_unlock(&surface_queue->lock);
                        return 1;