From de5826d6a2928ef481f9df56f011ae32b2164e89 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Thu, 29 Jun 2017 18:33:14 +0900 Subject: [PATCH] surface_queue: added queue cancel acquire/dequeue Change-Id: I0857b16141894eaf6f06a3b1584e971ac380a513 --- src/tbm_surface_queue.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++- src/tbm_surface_queue.h | 8 +++ 2 files changed, 150 insertions(+), 1 deletion(-) diff --git a/src/tbm_surface_queue.c b/src/tbm_surface_queue.c index 1dadcb0..e0b412e 100644 --- a/src/tbm_surface_queue.c +++ b/src/tbm_surface_queue.c @@ -1120,6 +1120,76 @@ tbm_surface_queue_enqueue(tbm_surface_queue_h } tbm_surface_queue_error_e +tbm_surface_queue_cancel_dequeue(tbm_surface_queue_h + surface_queue, tbm_surface_h surface) +{ + queue_node *node; + int queue_type; + + _tbm_surf_queue_mutex_lock(); + + TBM_SURF_QUEUE_RETURN_VAL_IF_FAIL(_tbm_surface_queue_is_valid(surface_queue), + TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_SURF_QUEUE_RETURN_VAL_IF_FAIL(surface != NULL, + TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE); + + pthread_mutex_lock(&surface_queue->lock); + + TBM_QUEUE_TRACE("tbm_surface_queue(%p) tbm_surface(%p)\n", surface_queue, surface); + + node = _queue_get_node(surface_queue, 0, surface, &queue_type); + if (node == NULL || queue_type != NODE_LIST) { + TBM_LOG_E("tbm_surface_queue_release::Surface is existed in free_queue or dirty_queue node:%p, type:%d\n", + node, queue_type); + pthread_mutex_unlock(&surface_queue->lock); + + _tbm_surf_queue_mutex_unlock(); + return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; + } + + if (surface_queue->queue_size < surface_queue->num_attached) { + TBM_QUEUE_TRACE("deatch tbm_surface_queue(%p) surface(%p)\n", surface_queue, node->surface); + + if (surface_queue->impl && surface_queue->impl->need_detach) + surface_queue->impl->need_detach(surface_queue, node); + else + _tbm_surface_queue_detach(surface_queue, surface); + + pthread_mutex_unlock(&surface_queue->lock); + + _tbm_surf_queue_mutex_unlock(); + + _trace_emit(surface_queue, &surface_queue->trace_noti, surface, TBM_SURFACE_QUEUE_TRACE_CANCEL_DEQUEUE); + + return TBM_SURFACE_QUEUE_ERROR_NONE; + } + + if (surface_queue->impl && surface_queue->impl->release) + surface_queue->impl->release(surface_queue, node); + else + _tbm_surface_queue_release(surface_queue, node, 1); + + if (_queue_is_empty(&surface_queue->free_queue)) { + pthread_mutex_unlock(&surface_queue->lock); + + TBM_LOG_E("surface_queue->free_queue is empty.\n"); + _tbm_surf_queue_mutex_unlock(); + return TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE; + } + + node->type = QUEUE_NODE_TYPE_RELEASE; + + pthread_mutex_unlock(&surface_queue->lock); + pthread_cond_signal(&surface_queue->free_cond); + + _tbm_surf_queue_mutex_unlock(); + + _trace_emit(surface_queue, &surface_queue->trace_noti, surface, TBM_SURFACE_QUEUE_TRACE_CANCEL_DEQUEUE); + + return TBM_SURFACE_QUEUE_ERROR_NONE; +} + +tbm_surface_queue_error_e tbm_surface_queue_dequeue(tbm_surface_queue_h surface_queue, tbm_surface_h *surface) { @@ -1311,6 +1381,61 @@ tbm_surface_queue_release(tbm_surface_queue_h } tbm_surface_queue_error_e +tbm_surface_queue_cancel_acquire(tbm_surface_queue_h + surface_queue, tbm_surface_h surface) +{ + queue_node *node; + int queue_type; + + _tbm_surf_queue_mutex_lock(); + + TBM_SURF_QUEUE_RETURN_VAL_IF_FAIL(_tbm_surface_queue_is_valid(surface_queue), + TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE); + TBM_SURF_QUEUE_RETURN_VAL_IF_FAIL(surface != NULL, + TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE); + + pthread_mutex_lock(&surface_queue->lock); + + TBM_QUEUE_TRACE("tbm_surface_queue(%p) tbm_surface(%p)\n", surface_queue, surface); + + node = _queue_get_node(surface_queue, 0, surface, &queue_type); + if (node == NULL || queue_type != NODE_LIST) { + TBM_LOG_E("tbm_surface_queue_enqueue::Surface is existed in free_queue or dirty_queue node:%p, type:%d\n", + node, queue_type); + pthread_mutex_unlock(&surface_queue->lock); + + _tbm_surf_queue_mutex_unlock(); + return TBM_SURFACE_QUEUE_ERROR_ALREADY_EXIST; + } + + if (surface_queue->impl && surface_queue->impl->enqueue) + surface_queue->impl->enqueue(surface_queue, node); + else + _tbm_surface_queue_enqueue(surface_queue, node, 1); + + if (_queue_is_empty(&surface_queue->dirty_queue)) { + TBM_LOG_E("enqueue surface but queue is empty node:%p\n", node); + pthread_mutex_unlock(&surface_queue->lock); + + _tbm_surf_queue_mutex_unlock(); + return TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE; + } + + node->type = QUEUE_NODE_TYPE_ENQUEUE; + + pthread_mutex_unlock(&surface_queue->lock); + pthread_cond_signal(&surface_queue->dirty_cond); + + _tbm_surf_queue_mutex_unlock(); + + _trace_emit(surface_queue, &surface_queue->trace_noti, surface, TBM_SURFACE_QUEUE_TRACE_CANCEL_ACQUIRE); + + _notify_emit(surface_queue, &surface_queue->acquirable_noti); + + return TBM_SURFACE_QUEUE_ERROR_NONE; +} + +tbm_surface_queue_error_e tbm_surface_queue_acquire(tbm_surface_queue_h surface_queue, tbm_surface_h *surface) { @@ -1716,6 +1841,8 @@ tbm_surface_queue_get_trace_surface_num( case TBM_SURFACE_QUEUE_TRACE_RELEASE: *num = _tbm_surface_queue_get_node_count(surface_queue, QUEUE_NODE_TYPE_RELEASE); break; + default: + break; } pthread_mutex_unlock(&surface_queue->lock); @@ -1894,6 +2021,20 @@ __tbm_queue_sequence_enqueue(tbm_surface_queue_h surface_queue, } } +static void +__tbm_queue_sequence_release(tbm_surface_queue_h surface_queue, + queue_node *node) +{ + tbm_queue_sequence *data = (tbm_queue_sequence *)surface_queue->impl_data; + + if (node->priv_flags) { + node->priv_flags = 0; + _queue_node_pop(&data->dequeue_list, node); + } + + _tbm_surface_queue_release(surface_queue, node, 1); +} + static queue_node * __tbm_queue_sequence_dequeue(tbm_surface_queue_h surface_queue) @@ -1916,7 +2057,7 @@ static const tbm_surface_queue_interface tbm_queue_sequence_impl = { __tbm_queue_sequence_destroy, __tbm_queue_sequence_need_attach, __tbm_queue_sequence_enqueue, - NULL, /*__tbm_queue_sequence_release*/ + __tbm_queue_sequence_release, __tbm_queue_sequence_dequeue, NULL, /*__tbm_queue_sequence_acquire*/ NULL, /*__tbm_queue_sequence_need_dettach*/ diff --git a/src/tbm_surface_queue.h b/src/tbm_surface_queue.h index 216bde6..1db6266 100644 --- a/src/tbm_surface_queue.h +++ b/src/tbm_surface_queue.h @@ -51,6 +51,8 @@ typedef enum { TBM_SURFACE_QUEUE_TRACE_ENQUEUE = 2, TBM_SURFACE_QUEUE_TRACE_ACQUIRE = 3, TBM_SURFACE_QUEUE_TRACE_RELEASE = 4, + TBM_SURFACE_QUEUE_TRACE_CANCEL_DEQUEUE = 5, + TBM_SURFACE_QUEUE_TRACE_CANCEL_ACQUIRE = 6, } tbm_surface_queue_trace; typedef struct _tbm_surface_queue *tbm_surface_queue_h; @@ -74,12 +76,18 @@ extern "C" { tbm_surface_queue_error_e tbm_surface_queue_enqueue( tbm_surface_queue_h surface_queue, tbm_surface_h surface); +tbm_surface_queue_error_e tbm_surface_queue_cancel_dequeue( + tbm_surface_queue_h surface_queue, tbm_surface_h surface); + tbm_surface_queue_error_e tbm_surface_queue_dequeue( tbm_surface_queue_h surface_queue, tbm_surface_h *surface); tbm_surface_queue_error_e tbm_surface_queue_release( tbm_surface_queue_h surface_queue, tbm_surface_h surface); +tbm_surface_queue_error_e tbm_surface_queue_cancel_acquire( + tbm_surface_queue_h surface_queue, tbm_surface_h surface); + tbm_surface_queue_error_e tbm_surface_queue_acquire( tbm_surface_queue_h surface_queue, tbm_surface_h *surface); -- 2.7.4