Fixed the deadlock issue 34/248434/2
authorInHong Han <inhong1.han@samsung.com>
Thu, 26 Nov 2020 11:43:28 +0000 (20:43 +0900)
committerInHong Han <inhong1.han@samsung.com>
Thu, 26 Nov 2020 12:31:31 +0000 (21:31 +0900)
To prevent the deadlock issue, modified not to pass the key event to IME if there are many requests in the queue.

Change-Id: Ib5a66d0f768e22f8e822ebda34e17ad7a06f0f74

ism/extras/wayland_immodule/wayland_imcontext.c

index a076145..871bb2d 100644 (file)
@@ -56,6 +56,7 @@
 
 #define HIDE_TIMER_INTERVAL     0.05
 #define WAIT_FOR_FILTER_DONE_SECOND 1.3
+#define MAX_WAIT_FOR_WL_SERVER 5.0
 
 #define MOD_SHIFT_MASK      0x01
 #define MOD_CAPS_MASK       0x02
@@ -146,6 +147,7 @@ static void set_autocapital (Ecore_IMF_Context *ctx);
 
 static Eina_Bool g_key_rate_checked = EINA_FALSE, g_focused = EINA_FALSE;
 static double g_original_key_rate = 0.0, g_original_key_delay = 0.0, g_desired_key_rate = 0.0;
+static double g_filter_event_elapsed_time = 0.0;
 //
 
 typedef struct __LanguageInfo {
@@ -3369,6 +3371,15 @@ _ecore_imf_modifier_to_ecore_key_modifier(Ecore_IMF_Keyboard_Modifiers modifiers
 }
 #endif
 
+static Eina_Bool
+_check_filter_event(WaylandIMContext *imcontext)
+{
+    int next_serial = imcontext->serial + 1;
+    double waiting_time = g_filter_event_elapsed_time * (next_serial - imcontext->last_key_event_filter.serial);
+
+    return (waiting_time > MAX_WAIT_FOR_WL_SERVER ? EINA_FALSE : EINA_TRUE);
+}
+
 Eina_Bool
 wayland_im_context_filter_event(Ecore_IMF_Context    *ctx,
                                 Ecore_IMF_Event_Type  type,
@@ -3452,6 +3463,12 @@ wayland_im_context_filter_event(Ecore_IMF_Context    *ctx,
                 break;
             }
 
+            if (!_check_filter_event(imcontext)) {
+                LOGE("elapsed time : %.3f ms, serial (last, require) : (%d, %d)", g_filter_event_elapsed_time * 1000, imcontext->last_key_event_filter.serial, imcontext->serial + 1);
+                ret = EINA_TRUE;
+                break;
+            }
+
             int serial = imcontext->serial++;
             double start_time = ecore_time_get();
 
@@ -3506,6 +3523,11 @@ wayland_im_context_filter_event(Ecore_IMF_Context    *ctx,
                     wl_event_queue_destroy(queue);
                 }
 
+                if (g_filter_event_elapsed_time == 0)
+                    g_filter_event_elapsed_time = ecore_time_get() - start_time;
+                else
+                    g_filter_event_elapsed_time = (g_filter_event_elapsed_time + (ecore_time_get() - start_time)) / 2;
+
                 LOGD ("elapsed : %.3f ms, serial (last, require) : (%d, %d)", (ecore_time_get() - start_time)*1000, imcontext->last_key_event_filter.serial, serial);
             }
         } while (0);