Add mutex for device list in device manager 82/295182/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 22 May 2023 11:19:47 +0000 (20:19 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 4 Jul 2023 07:31:48 +0000 (07:31 +0000)
Change-Id: I12be5d405b0734f3d282dd3cf8914789147d343f
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/e_comp_wl.c
src/bin/e_devicemgr.c
src/bin/e_devicemgr.h
src/bin/e_devicemgr_input.c

index 2a67704..008a773 100644 (file)
@@ -856,6 +856,7 @@ _e_comp_wl_device_send_event_device(E_Client *ec, Evas_Device *dev, uint32_t tim
 
    serial = wl_display_next_serial(e_comp_wl->wl.disp);
    wc = wl_resource_get_client(ec->comp_data->surface);
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
      {
         if (!eina_streq(input_dev->identifier, dev_name) || (input_dev->clas != dev_class)) continue;
@@ -871,6 +872,7 @@ _e_comp_wl_device_send_event_device(E_Client *ec, Evas_Device *dev, uint32_t tim
                }
           }
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 }
 
 static void
@@ -910,6 +912,7 @@ _e_comp_wl_send_event_device(struct wl_client *wc, uint32_t timestamp, Ecore_Dev
 
    dev_name = ecore_device_identifier_get(dev);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
      {
         if (!eina_streq(input_dev->identifier, dev_name) ||
@@ -922,6 +925,7 @@ _e_comp_wl_send_event_device(struct wl_client *wc, uint32_t timestamp, Ecore_Dev
              tizen_input_device_send_event_device(dev_res, serial, input_dev->identifier, timestamp);
           }
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 }
 
 static void
@@ -936,6 +940,7 @@ _e_comp_wl_send_event_e_device(struct wl_client *wc, uint32_t timestamp, E_Devic
 
    dev_name = e_device_identifier_get(dev);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
      {
         if (!eina_streq(input_dev->identifier, dev_name) ||
@@ -948,6 +953,7 @@ _e_comp_wl_send_event_e_device(struct wl_client *wc, uint32_t timestamp, E_Devic
              tizen_input_device_send_event_device(dev_res, serial, input_dev->identifier, timestamp);
           }
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 }
 
 static void
@@ -1024,6 +1030,7 @@ _e_comp_wl_device_send_axis(const char *dev_name, Evas_Device_Class dev_class, E
    f_value = wl_fixed_from_double(value);
    wc = wl_resource_get_client(ec->comp_data->surface);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
      {
         if ((strcmp(input_dev->identifier, dev_name)) || (input_dev->clas != (Ecore_Device_Class)dev_class)) continue;
@@ -1033,6 +1040,7 @@ _e_comp_wl_device_send_axis(const char *dev_name, Evas_Device_Class dev_class, E
              tizen_input_device_send_axis(dev_res, axis_type, f_value);
           }
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 }
 
 static void
index 4213e54..3cb5220 100644 (file)
@@ -130,6 +130,8 @@ e_devicemgr_init(void)
    e_devicemgr_conf_init(dconfig);
    e_devicemgr->dconfig = dconfig;
 
+   g_mutex_init(&e_devicemgr->device_list_mutex);
+
    res = e_devicemgr_wl_init();
    EINA_SAFETY_ON_FALSE_GOTO(res, wl_failed);
 
@@ -166,6 +168,7 @@ failed:
 EINTERN int
 e_devicemgr_shutdown(void)
 {
+   g_mutex_clear(&e_devicemgr->device_list_mutex);
    eina_log_domain_unregister(_devicemgr_log_dom);
    _devicemgr_log_dom = -1;
    if (e_devicemgr->dconfig)
index 60e755e..f1cbac8 100644 (file)
@@ -48,6 +48,7 @@ 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;
index 8fca4bc..f9e309b 100644 (file)
@@ -198,6 +198,7 @@ _e_devicemgr_input_device_add(const char *name, const char *identifier, const ch
    EINA_SAFETY_ON_NULL_RETURN(identifier);
    EINA_SAFETY_ON_NULL_RETURN(e_devicemgr);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
      {
         if (!dev->name) continue;
@@ -206,9 +207,11 @@ _e_devicemgr_input_device_add(const char *name, const char *identifier, const ch
             (!strcmp(dev->name, name)) &&
             (!strcmp(dev->identifier, identifier)))
           {
+             g_mutex_unlock(&e_devicemgr->device_list_mutex);
              return;
           }
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 
    if (!(dev = E_NEW(E_Devicemgr_Input_Device, 1))) return;
    dev->name = eina_stringshare_add(name);
@@ -217,7 +220,9 @@ _e_devicemgr_input_device_add(const char *name, const char *identifier, const ch
    dev->clas = clas;
    dev->subclas = subclas;
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    e_devicemgr->device_list = eina_list_append(e_devicemgr->device_list, dev);
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 
    if (dev->clas == ECORE_DEVICE_CLASS_MOUSE)
      e_devicemgr->last_device_ptr = dev;
@@ -264,6 +269,7 @@ _e_devicemgr_input_device_del(const char *name, const char *identifier, const ch
    EINA_SAFETY_ON_NULL_RETURN(name);
    EINA_SAFETY_ON_NULL_RETURN(identifier);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
      {
         if (!dev->name) continue;
@@ -273,6 +279,7 @@ _e_devicemgr_input_device_del(const char *name, const char *identifier, const ch
             (!strcmp(dev->identifier, identifier)))
           break;
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
    if (!dev)
      {
         return;
@@ -285,7 +292,9 @@ _e_devicemgr_input_device_del(const char *name, const char *identifier, const ch
    if (dev->identifier) eina_stringshare_del(dev->identifier);
    if (dev->seat_name) eina_stringshare_del(dev->seat_name);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    e_devicemgr->device_list = eina_list_remove(e_devicemgr->device_list, dev);
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 
    if (e_devicemgr->last_device_ptr == dev)
      e_devicemgr->last_device_ptr = NULL;
@@ -311,6 +320,7 @@ _e_devicemgr_input_device_update(Ecore_Device *dev)
    dev_identifier = (char *)ecore_device_identifier_get(dev);
    EINA_SAFETY_ON_NULL_RETURN(dev_identifier);
 
+   g_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, data)
      {
         if (data->clas == ecore_device_class_get(dev) && data->identifier)
@@ -320,10 +330,12 @@ _e_devicemgr_input_device_update(Ecore_Device *dev)
                   data->subclas = ecore_device_subclass_get(dev);
 
                   e_devicemgr_wl_device_update(data);
+                  g_mutex_unlock(&e_devicemgr->device_list_mutex);
                   return;
                }
           }
      }
+   g_mutex_unlock(&e_devicemgr->device_list_mutex);
 }
 
 static Eina_Bool