utils_gthread: do not make data into NULL before the source is destroyed 16/295916/2
authorJoonbum Ko <joonbum.ko@samsung.com>
Mon, 17 Jul 2023 07:35:16 +0000 (16:35 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Mon, 17 Jul 2023 08:26:58 +0000 (17:26 +0900)
 - Even if thread call the g_source_destroy & unref it, it may not be destroyed
  immediately. (waiting for dispatch in g_main_context)
 - source->data will be changed to NULL only when it destroyed perfectly.

Change-Id: Iecf8ce7599a0ad92346fe7dc802bfcebbb7cd25c
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_utils_gthread.c

index 6020a67..e9f506b 100644 (file)
@@ -327,8 +327,6 @@ __gsource_remove_and_destroy(tpl_gsource *source)
        g_source_remove_unix_fd(&source->gsource, source->tag);
        g_source_destroy(&source->gsource);
        g_source_unref(&source->gsource);
-
-       source->data = NULL;
 }
 
 void
@@ -339,7 +337,6 @@ tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread)
        if (g_source_is_destroyed(&source->gsource)) {
                TPL_WARN("gsource(%p) already has been destroyed.",
                                 source);
-               source->data = NULL;
                return;
        }
 
@@ -358,6 +355,16 @@ tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread)
        }
 
        if (!destroy_in_thread) {
+               if (source->fd_type == FD_TYPE_FENCE &&
+                       source->type == SOURCE_TYPE_DISPOSABLE) {
+                       TPL_LOG_D("[GSOURCE][DESTROY]", "tpl_gsource(%p) type(%d)",
+                                         source, source->type);
+
+                       g_source_remove_unix_fd(&source->gsource, source->tag);
+                       source->data = NULL;
+                       g_source_destroy(&source->gsource);
+                       g_source_unref(&source->gsource);
+               }
                __gsource_remove_and_destroy(source);
        }