Add mutex for last device keyboard variable 83/295183/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 22 May 2023 12:01:45 +0000 (21:01 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 4 Jul 2023 07:31:56 +0000 (07:31 +0000)
Change-Id: I8a48a1fc0902a86c4f52f84ef49618ba03a5f62a
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/e_comp_wl.c
src/bin/e_comp_wl.h
src/bin/e_devicemgr.c
src/bin/e_devicemgr.h
src/bin/e_devicemgr_input.c

index 008a773957130cee14bc38fbd0eed88706fb46ee..ab028d8cb5ab37f3d1285623970a70e1cb5d8ad1 100644 (file)
@@ -760,12 +760,16 @@ _e_comp_wl_touch_cancel(void)
 static E_Devicemgr_Input_Device *
 _e_comp_wl_device_last_device_get(Ecore_Device_Class dev_class)
 {
+   E_Devicemgr_Input_Device *last_kbd = NULL;
    switch (dev_class)
      {
       case ECORE_DEVICE_CLASS_MOUSE:
          return e_devicemgr->last_device_ptr;
       case ECORE_DEVICE_CLASS_KEYBOARD:
-         return e_devicemgr->last_device_kbd;
+         g_mutex_lock(&e_devicemgr->last_device_kbd_mutex);
+         last_kbd = e_devicemgr->last_device_kbd;
+         g_mutex_unlock(&e_devicemgr->last_device_kbd_mutex);
+         return last_kbd;
       case ECORE_DEVICE_CLASS_TOUCH:
          return e_devicemgr->last_device_touch;
       default:
@@ -783,7 +787,9 @@ _e_comp_wl_device_last_device_set(Ecore_Device_Class dev_class, E_Devicemgr_Inpu
          e_devicemgr->last_device_ptr = device;
          break;
       case ECORE_DEVICE_CLASS_KEYBOARD:
+         g_mutex_lock(&e_devicemgr->last_device_kbd_mutex);
          e_devicemgr->last_device_kbd = device;
+         g_mutex_unlock(&e_devicemgr->last_device_kbd_mutex);
          break;
       case ECORE_DEVICE_CLASS_TOUCH:
          e_devicemgr->last_device_touch = device;
@@ -796,12 +802,17 @@ _e_comp_wl_device_last_device_set(Ecore_Device_Class dev_class, E_Devicemgr_Inpu
 static E_Devicemgr_Input_Device *
 _e_comp_wl_device_client_last_device_get(E_Client *ec, Ecore_Device_Class dev_class)
 {
+   E_Devicemgr_Input_Device *last_kbd = NULL;
+
    switch (dev_class)
      {
       case ECORE_DEVICE_CLASS_MOUSE:
          return ec->comp_data->last_device_ptr;
       case ECORE_DEVICE_CLASS_KEYBOARD:
-         return ec->comp_data->last_device_kbd;
+         g_mutex_lock(&ec->comp_data->last_device_kbd_mutex);
+         last_kbd = ec->comp_data->last_device_kbd;
+         g_mutex_unlock(&ec->comp_data->last_device_kbd_mutex);
+         return last_kbd;
       case ECORE_DEVICE_CLASS_TOUCH:
          return ec->comp_data->last_device_touch;
       default:
@@ -819,7 +830,9 @@ _e_comp_wl_device_client_last_device_set(E_Client *ec, Ecore_Device_Class dev_cl
          ec->comp_data->last_device_ptr = device;
          break;
       case ECORE_DEVICE_CLASS_KEYBOARD:
+         g_mutex_lock(&ec->comp_data->last_device_kbd_mutex);
          ec->comp_data->last_device_kbd = device;
+         g_mutex_unlock(&ec->comp_data->last_device_kbd_mutex);
          break;
       case ECORE_DEVICE_CLASS_TOUCH:
          ec->comp_data->last_device_touch = device;
@@ -3879,6 +3892,8 @@ _e_comp_wl_client_cb_new(void *data EINA_UNUSED, E_Client *ec)
 
    e_pixmap_cdata_set(ec->pixmap, ec->comp_data);
 
+   g_mutex_init(&ec->comp_data->last_device_kbd_mutex);
+
 end:
    TRACE_DS_END();
 }
@@ -3894,6 +3909,8 @@ _e_comp_wl_client_cb_del(void *data EINA_UNUSED, E_Client *ec)
 
    TRACE_DS_BEGIN(COMP_WL:CLIENT DEL CB);
 
+   g_mutex_clear(&ec->comp_data->last_device_kbd_mutex);
+
    _e_comp_wl_hook_call(E_COMP_WL_HOOK_DEL, ec);
 
    if ((!ec->already_unparented) && (ec->comp_data->reparented))
index 2db9b2d24cc86e7da83cc68ddb321e35b2783068..44556d35080d65a25b11e5203ef1c3b93300d0b3 100644 (file)
@@ -523,6 +523,7 @@ struct _E_Comp_Wl_Client_Data
 
    Eina_Bool wtz_surface_assigned;
    struct wl_list pointer_constraints;
+   GMutex last_device_kbd_mutex;
 };
 
 struct _E_Comp_Wl_Output
index 3cb52206dac7245bd44fbddc3ebdb232348e9376..d4148c4f2a023ecebf8c943c097c68c4419ab928 100644 (file)
@@ -131,6 +131,7 @@ e_devicemgr_init(void)
    e_devicemgr->dconfig = dconfig;
 
    g_mutex_init(&e_devicemgr->device_list_mutex);
+   g_mutex_init(&e_devicemgr->last_device_kbd_mutex);
 
    res = e_devicemgr_wl_init();
    EINA_SAFETY_ON_FALSE_GOTO(res, wl_failed);
@@ -169,6 +170,8 @@ EINTERN int
 e_devicemgr_shutdown(void)
 {
    g_mutex_clear(&e_devicemgr->device_list_mutex);
+   g_mutex_clear(&e_devicemgr->last_device_kbd_mutex);
+
    eina_log_domain_unregister(_devicemgr_log_dom);
    _devicemgr_log_dom = -1;
    if (e_devicemgr->dconfig)
index f1cbac88ed18824e2d0ceae709799d0f57ddcb7c..9108350bb51c6659604322d9cdc82d21b1a0f881 100644 (file)
@@ -48,7 +48,6 @@ struct _E_Devicemgr
 
    Eina_List *handlers;
 
-   GMutex device_list_mutex;
    Eina_List *device_list;
    E_Devicemgr_Input_Device *last_device_ptr;
    E_Devicemgr_Input_Device *last_device_touch;
@@ -87,6 +86,8 @@ struct _E_Devicemgr
    Eina_List *watched_clients;
 
    int max_touch_count;
+   GMutex device_list_mutex;
+   GMutex last_device_kbd_mutex;
 };
 
 struct _E_Devicemgr_Intercept_Hook
index f9e309b9467e8f8d087518b312684a61205c451c..88a5720d73e4f94477cdacc0b9499dae5b16ef4a 100644 (file)
@@ -251,9 +251,12 @@ _e_devicemgr_input_device_add(const char *name, const char *identifier, const ch
           }
      }
 
+   g_mutex_lock(&e_devicemgr->last_device_kbd_mutex);
    if (!e_devicemgr->last_device_kbd && dev->clas == ECORE_DEVICE_CLASS_KEYBOARD)
      e_devicemgr->last_device_kbd = dev;
 
+   g_mutex_unlock(&e_devicemgr->last_device_kbd_mutex);
+
    e_devicemgr_inputgen_device_ready_send(dev);
    e_devicemgr_wl_device_add(dev);
    e_devicemgr_inputgen_get_device_info(dev);