[UI Thread] Use tizen glib context 75/273175/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 31 Mar 2022 06:59:16 +0000 (15:59 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 31 Mar 2022 07:18:19 +0000 (16:18 +0900)
After this patch is applied, ecore main loop dispaches tizen glib context.
The application core sets the tizen glib context using setenv() with
"TIZEN_GLIB_CONTEXT".

Change-Id: Ib1405fe6fb8a646a946b8c666b7d0ef74e0bfcc4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/ecore/ecore_glib.c
src/lib/ecore/ecore_main.c

index dea98ff..02678e1 100644 (file)
@@ -229,6 +229,24 @@ error:
             (ecore_fds, rfds, wfds, efds, ecore_timeout);
 }
 
+static GMainContext *
+_ecore_glib_get_tizen_context(void)
+{
+   static GMainContext *ctx;
+   static int initialized;
+   const char *env;
+
+   if (initialized)
+     return ctx;
+
+   env = getenv("TIZEN_GLIB_CONTEXT");
+   if (env)
+     ctx = (GMainContext *)strtoul(env, NULL, 10);
+
+   initialized = 1;
+   return ctx;
+}
+
 static int
 _ecore_glib_select(int             ecore_fds,
                    fd_set         *rfds,
@@ -239,11 +257,11 @@ _ecore_glib_select(int             ecore_fds,
    GMainContext *ctx;
    int ret;
 
-   //TIZEN_ONLY(220322): Use thread default context
-   /* If a process sets the thread default context using the g_main_context_push_thread_default(),
+   //TIZEN_ONLY(220331): Use tizen glib context
+   /* If a process sets the tizen glib context using the getenv(),
     * this function uses thread default context instead of the global default context.
     */
-   ctx = g_main_context_get_thread_default();
+   ctx = _ecore_glib_get_tizen_context();
    if (!ctx)
      ctx = g_main_context_default();
 
index 0e2d947..93d2a87 100644 (file)
@@ -1275,6 +1275,27 @@ _ecore_main_loop_iterate_may_block(Eo *obj, Efl_Loop_Data *pd, int may_block)
    return 0;
 }
 
+#ifdef USR_G_MAIN_LOOP
+//TIZEN_ONLY(220331): Use tizen glib context
+/* If a process sets the tizen glib context using the getenv(),
+ * this function uses the tizen glib context instead of the global default context.
+ */
+static GMainContext *
+_ecore_glib_get_tizen_context(void)
+{
+   const char *env;
+   GMainContext *ctx;
+
+   env = getenv("TIZEN_GLIB_CONTEXT");
+   if (env)
+     ctx = (GMainContext *)strtoul(env, NULL, 10);
+   else
+     ctx = NULL;
+
+   return ctx;
+}
+#endif
+
 void
 _ecore_main_loop_begin(Eo *obj, Efl_Loop_Data *pd)
 {
@@ -1304,13 +1325,13 @@ _ecore_main_loop_begin(Eo *obj, Efl_Loop_Data *pd)
 #else
              if (!pd->do_quit)
                {
-                  //TIZEN_ONLY(220322): Use thread default context
-                  /* If a process sets the thread default context using the g_main_context_push_thread_default(),
-                   * this function uses thread default context instead of the global default context.
+                  //TIZEN_ONLY(220331): Use tizen glib context
+                  /* If a process sets the tizen glib context using the getenv(),
+                   * this function uses the tizen glib context instead of the global default context.
                    */
                   if (!ecore_main_loop) {
                     ecore_main_loop = g_main_loop_new(
-                        g_main_context_get_thread_default(), FALSE);
+                        _ecore_glib_get_tizen_context(), FALSE);
                   }
                   g_main_loop_run(ecore_main_loop);
                }
@@ -1345,13 +1366,13 @@ _ecore_main_loop_begin(Eo *obj, Efl_Loop_Data *pd)
 #else
         if (!pd->do_quit)
           {
-             //TIZEN_ONLY(220322): Use thread default context
-             /* If a process sets the thread default context using the g_main_context_push_thread_default(),
-              * this function uses thread default context instead of the global default context.
+             //TIZEN_ONLY(220331): Use tizen glib context
+             /* If a process sets the tizen glib context using the getenv(),
+              * this function uses the tizen glib context instead of the global default context.
               */
              if (!ecore_main_loop) {
                ecore_main_loop = g_main_loop_new(
-                  g_main_context_get_thread_default(), 1);
+                  _ecore_glib_get_tizen_context(), 1);
              }
              g_main_loop_run(ecore_main_loop);
           }