surface_queue: use magic number for checking valid of surface_queue 57/250757/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Mon, 4 Jan 2021 09:13:50 +0000 (18:13 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Thu, 7 Jan 2021 11:07:04 +0000 (20:07 +0900)
Change-Id: Ie244b00d8c03b6b56815b1506270ea99b4be76cf

src/tbm_surface_queue.c

index ef63887..ee93127 100644 (file)
@@ -39,7 +39,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define DIRTY_QUEUE    2
 #define NODE_LIST      4
 
-static tbm_bufmgr g_surf_queue_bufmgr;
+#define TBM_SURFACE_QUEUE_MAGIC 0xBF031234
+
 static pthread_mutex_t tbm_surf_queue_lock = PTHREAD_MUTEX_INITIALIZER;
 void _tbm_surface_queue_mutex_unlock(void);
 
@@ -116,6 +117,7 @@ typedef struct _tbm_surface_queue_interface {
 } tbm_surface_queue_interface;
 
 struct _tbm_surface_queue {
+       unsigned int magic;
        int width;
        int height;
        int format;
@@ -147,8 +149,6 @@ struct _tbm_surface_queue {
        tbm_surface_free_cb free_cb;
        void *alloc_cb_data;
 
-       struct list_head item_link; /* link of surface queue */
-
        int modes;
        unsigned int enqueue_sync_count;
        unsigned int acquire_sync_count;
@@ -166,51 +166,29 @@ _tbm_surf_queue_mutex_unlock(void)
        pthread_mutex_unlock(&tbm_surf_queue_lock);
 }
 
-static void
-_init_tbm_surf_queue_bufmgr(void)
-{
-       g_surf_queue_bufmgr = tbm_bufmgr_init(-1);
-}
-
-static void
-_deinit_tbm_surf_queue_bufmgr(void)
+static int
+_tbm_surface_queue_magic_check(tbm_surface_queue_h surface_queue)
 {
-       if (!g_surf_queue_bufmgr)
-               return;
+       if (surface_queue->magic != TBM_SURFACE_QUEUE_MAGIC)
+               return 0;
 
-       tbm_bufmgr_deinit(g_surf_queue_bufmgr);
-       g_surf_queue_bufmgr = NULL;
+       return 1;
 }
 
 static int
 _tbm_surface_queue_is_valid(tbm_surface_queue_h surface_queue)
 {
-       tbm_surface_queue_h old_data = NULL;
-
-       if (surface_queue == NULL) {
+       if (!surface_queue) {
                TBM_ERR("error: surface_queue is NULL.\n");
                return 0;
        }
 
-       if (g_surf_queue_bufmgr == NULL) {
-               TBM_ERR("error: g_surf_queue_bufmgr is NULL.\n");
-               return 0;
-       }
-
-       if (LIST_IS_EMPTY(&g_surf_queue_bufmgr->surf_queue_list)) {
-               TBM_ERR("error: surf_queue_list is empty\n");
+       if (!_tbm_surface_queue_magic_check(surface_queue)) {
+               TBM_ERR("error: Invalid tbm_surface_queue(%p)\n", surface_queue);
                return 0;
        }
 
-       LIST_FOR_EACH_ENTRY(old_data, &g_surf_queue_bufmgr->surf_queue_list,
-                               item_link) {
-               if (old_data == surface_queue)
-                       return 1;
-       }
-
-       TBM_ERR("error: Invalid tbm_surface_queue(%p)\n", surface_queue);
-
-       return 0;
+       return 1;
 }
 
 static queue_node *
@@ -601,9 +579,6 @@ _tbm_surface_queue_init(tbm_surface_queue_h surface_queue,
        TBM_RETURN_IF_FAIL(surface_queue != NULL);
        TBM_RETURN_IF_FAIL(impl != NULL);
 
-       if (!g_surf_queue_bufmgr)
-               _init_tbm_surf_queue_bufmgr();
-
        pthread_mutex_init(&surface_queue->lock, NULL);
 
        pthread_condattr_init(&free_attr);
@@ -616,6 +591,7 @@ _tbm_surface_queue_init(tbm_surface_queue_h surface_queue,
        pthread_cond_init(&surface_queue->dirty_cond, &dirty_attr);
        pthread_condattr_destroy(&dirty_attr);
 
+       surface_queue->magic = TBM_SURFACE_QUEUE_MAGIC;
        surface_queue->queue_size = queue_size;
        surface_queue->width = width;
        surface_queue->height = height;
@@ -639,8 +615,6 @@ _tbm_surface_queue_init(tbm_surface_queue_h surface_queue,
 
        if (surface_queue->impl && surface_queue->impl->init)
                surface_queue->impl->init(surface_queue);
-
-       LIST_ADD(&surface_queue->item_link, &g_surf_queue_bufmgr->surf_queue_list);
 }
 
 tbm_surface_queue_error_e
@@ -1707,7 +1681,7 @@ tbm_surface_queue_destroy(tbm_surface_queue_h surface_queue)
 
        TBM_TRACE_SURFACE_QUEUE("tbm_surface_queue(%p)\n", surface_queue);
 
-       LIST_DEL(&surface_queue->item_link);
+       surface_queue->magic = 0;
 
        LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->list, link)
                _queue_delete_node(surface_queue, node);
@@ -1729,9 +1703,6 @@ tbm_surface_queue_destroy(tbm_surface_queue_h surface_queue)
 
        free(surface_queue);
 
-       if (LIST_IS_EMPTY(&g_surf_queue_bufmgr->surf_queue_list))
-               _deinit_tbm_surf_queue_bufmgr();
-
        _tbm_surf_queue_mutex_unlock();
 }