tpl: Add check id after tpl_gthread_add_idle() 83/318883/1
authorTaeHyeon Jeong <thyeon.jeong@samsung.com>
Thu, 10 Oct 2024 08:52:29 +0000 (17:52 +0900)
committerTaeHyeon Jeong <thyeon.jeong@samsung.com>
Thu, 10 Oct 2024 09:00:29 +0000 (18:00 +0900)
Change-Id: Ib0376bfdae54df2e309365ca8e487d89053ca170

src/tpl_utils_gthread.c
src/tpl_wl_egl_thread.c

index a5c77bde983d146bd747b183c02b68c26d4a2410..a0b1fb74e0925d4f684b1f0e3093dfeab9c38522 100644 (file)
@@ -538,21 +538,24 @@ tpl_gthread_wait_idle(tpl_gthread *gthread)
        g_mutex_lock(&gthread->idle_mutex);
 
        id = tpl_gthread_add_idle(gthread, (tpl_gsource_func)_thread_idle_cb, gthread);
-
-       /* 500ms timeout */
-       end_time = g_get_monotonic_time() +
-                               (WAIT_IDLE_TIMEOUT * G_TIME_SPAN_MILLISECOND);
-       do {
-               ret = g_cond_wait_until(&gthread->idle_cond,
-                                                               &gthread->idle_mutex,
-                                                               end_time);
-               if (!ret) {
-                       tpl_gsource_remove(gthread, id);
-                       TPL_ERR("wait_idle timeout!");
-                       res = TPL_ERROR_TIME_OUT;
-                       break;
-               }
-       } while (!gthread->is_idle);
+       if (!id) {
+               TPL_WARN("Failed to attach idle gsource.");
+       } else {
+               /* 500ms timeout */
+               end_time = g_get_monotonic_time() +
+                                       (WAIT_IDLE_TIMEOUT * G_TIME_SPAN_MILLISECOND);
+               do {
+                       ret = g_cond_wait_until(&gthread->idle_cond,
+                                                                       &gthread->idle_mutex,
+                                                                       end_time);
+                       if (!ret) {
+                               tpl_gsource_remove(gthread, id);
+                               TPL_ERR("wait_idle timeout!");
+                               res = TPL_ERROR_TIME_OUT;
+                               break;
+                       }
+               } while (!gthread->is_idle);
+       }
 
        gthread->is_idle = TPL_FALSE;
 
index 76e602f9770b88ec5a92f9e33315b122aa07a58d..893fe78450e3b927d98cf855a1ef3885d4beda9f 100755 (executable)
@@ -2471,19 +2471,24 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
        wl_egl_surface->buffers_finalize_done = TPL_FALSE;
        id = tpl_gthread_add_idle(wl_egl_display->thread,
                                                          __idle_cb_buffers_finalize, wl_egl_surface);
-       tpl_gcond_timed_wait(&wl_egl_surface->surf_cond,
-                                                &wl_egl_surface->surf_mutex,
-                                                BUFFER_CLEAR_WAITING_TIMEOUT_MS)
-       {
-               if (wl_egl_surface->buffers_finalize_done)
-                       break;
-       } else {
-               tpl_gsource_remove(wl_egl_display->thread, id);
-               TPL_WARN("buffer clear timeout. wl_egl_surface(%p)", wl_egl_surface);
-
-               wl_egl_surface->buffers_finalize_done = TPL_TRUE;
+       if (!id) {
+               TPL_WARN("Failed to attach idle gsource. wl_egl_surface(%p)",
+                                wl_egl_surface);
                wl_egl_surface->need_force_release = TPL_TRUE;
+       } else {
+               tpl_gcond_timed_wait(&wl_egl_surface->surf_cond,
+                                                        &wl_egl_surface->surf_mutex,
+                                                        BUFFER_CLEAR_WAITING_TIMEOUT_MS)
+               {
+                       if (wl_egl_surface->buffers_finalize_done)
+                               break;
+               } else {
+                       tpl_gsource_remove(wl_egl_display->thread, id);
+                       TPL_WARN("buffer clear timeout. wl_egl_surface(%p)", wl_egl_surface);
+                       wl_egl_surface->need_force_release = TPL_TRUE;
+               }
        }
+       wl_egl_surface->buffers_finalize_done = TPL_TRUE;
 
        if (wl_egl_surface->surf_source) {
                // Send destroy mesage to thread
@@ -2869,16 +2874,22 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns,
                wl_egl_surface->buffers_commit_done = TPL_FALSE;
                id = tpl_gthread_add_idle(wl_egl_display->thread,
                                                                  __idle_cb_check_buffers_commit, wl_egl_surface);
-               tpl_gcond_timed_wait(&wl_egl_surface->surf_cond,
-                                                        &wl_egl_surface->surf_mutex,
-                                                        CHECK_COMMIT_TIMEOUT_MS)
-               {
-                       if (wl_egl_surface->buffers_commit_done)
-                               break;
+               if (!id) {
+                       TPL_WARN("Failed to attach idle gsource. wl_egl_surface(%p)",
+                                        wl_egl_surface);
                } else {
-                       tpl_gsource_remove(wl_egl_display->thread, id);
-                       TPL_WARN("wl_egl_surface(%p) timeout error occured", wl_egl_surface);
-                       _print_buffer_lists(wl_egl_surface);
+                       tpl_gcond_timed_wait(&wl_egl_surface->surf_cond,
+                                                                &wl_egl_surface->surf_mutex,
+                                                                CHECK_COMMIT_TIMEOUT_MS)
+                       {
+                               if (wl_egl_surface->buffers_commit_done)
+                                       break;
+                       } else {
+                               tpl_gsource_remove(wl_egl_display->thread, id);
+                               TPL_WARN("wl_egl_surface(%p) timeout error occured",
+                                                wl_egl_surface);
+                               _print_buffer_lists(wl_egl_surface);
+                       }
                }
 
                wl_egl_surface->buffers_commit_done = TPL_TRUE;