tpl_wayland_egl_thread: Added tpl_object_t to twe_wl_surf_source to use mutex lock. 04/135004/2
authorjoonbum.ko <joonbum.ko@samsung.com>
Fri, 12 May 2017 06:35:51 +0000 (15:35 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 21 Jun 2017 07:04:26 +0000 (16:04 +0900)
 - committed_buffers(tpl_list_t) wrapped in TPL_OBJECT_LOCK/UNLOCK to ensure thread safety of tpl_list_t.

Change-Id: Ia54a71bd4f11a3804a72450faca08ca0c8e63ff5
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index 882733d..1dd19c6 100644 (file)
@@ -10,6 +10,7 @@
 #include <glib-unix.h>
 
 #include "tpl_utils.h"
+#include "tpl_internal.h"
 #include "wayland-egl/wayland-egl-priv.h"
 #include "tpl_wayland_egl_thread.h"
 #include "tpl_utils.h"
@@ -59,6 +60,7 @@ struct _twe_wl_surf_source {
        int rotation;
        tpl_bool_t rotation_capability;
        tpl_bool_t vblank_done;
+       tpl_object_t obj; /* for mutex lock */
        tpl_list_t *committed_buffers;
        tdm_client_vblank *vblank;
        tbm_surface_queue_h tbm_queue;
@@ -543,8 +545,11 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source,
                        TPL_ERR("Failed to tdm_client_vblank_wait. tdm_err(%d)", tdm_err);
        }
 
-       if (surf_source->committed_buffers)
+       if (surf_source->committed_buffers) {
+               TPL_OBJECT_LOCK(&surf_source->obj);
                __tpl_list_push_back(surf_source->committed_buffers, tbm_surface);
+               TPL_OBJECT_UNLOCK(&surf_source->obj);
+       }
 }
 
 static void
@@ -615,6 +620,7 @@ _twe_thread_wl_surface_finalize(GSource *source)
        twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source;
 
        if (surf_source->committed_buffers) {
+               TPL_OBJECT_LOCK(&surf_source->obj);
                while (!__tpl_list_is_empty(surf_source->committed_buffers)) {
                        tbm_surface_h tbm_surface =
                                (tbm_surface_h)__tpl_list_pop_front(
@@ -625,8 +631,11 @@ _twe_thread_wl_surface_finalize(GSource *source)
 
                __tpl_list_free(surf_source->committed_buffers, NULL);
                surf_source->committed_buffers = NULL;
+               TPL_OBJECT_UNLOCK(&surf_source->obj);
        }
 
+       __tpl_object_fini(&surf_source->obj);
+
        g_source_remove_unix_fd(source, surf_source->tag);
 
        close(surf_source->event_fd);
@@ -800,6 +809,8 @@ twe_surface_add(twe_thread* thread,
        source->vblank_done = TPL_TRUE;
        source->committed_buffers = __tpl_list_alloc();
 
+       __tpl_object_init(&source->obj, TPL_OBJECT_SURFACE, NULL);
+
        wl_egl_window->private = (void *)source;
        wl_egl_window->resize_callback = (void *)__cb_resize_callback;
        wl_egl_window->rotate_callback = (void *)__cb_rotate_callback;
@@ -928,9 +939,11 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer)
                                TPL_ERR("tbm_surface(%p) tsq_err(%d)", tbm_surface, tsq_err);
 
                        if (surf_source->committed_buffers) {
+                               TPL_OBJECT_LOCK(&surf_source->obj);
                                __tpl_list_remove_data(surf_source->committed_buffers,
                                                                           (void *)tbm_surface,
                                                                           TPL_FIRST, NULL);
+                               TPL_OBJECT_UNLOCK(&surf_source->obj);
                        }
 
                        TPL_LOG_T("WL_EGL", "[REL] wl_buffer(%p) tbm_surface(%p) bo(%d)",