e_dbus_conn: do eldbus_connection_unref in the main thread, add a logic to do unref... 68/197368/1
authorSung-Jin Park <sj76.park@samsung.com>
Thu, 10 Jan 2019 07:47:08 +0000 (16:47 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 11 Jan 2019 01:31:44 +0000 (01:31 +0000)
Change-Id: Iae87d1903d2a0778c4c22f8902c20f20a7f8d94d
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
(cherry picked from commit f03ac88fdc39b7e4bf38065b3bab8c348b982e3e)

src/bin/e_dbus_conn.c
src/bin/e_dbus_conn.h

index 984616083ee760ff9fe05d29abdf419970219bbf..ad0aef06c99f67d79ed1acf33a77a64150ea35d3 100644 (file)
@@ -22,7 +22,10 @@ e_dbus_conn_connection_ref(Eldbus_Connection_Type type)
    /* Currently, ELDBUS_CONNECTION_TYPE_SYSTEM is being supported */
 
    if (e_dbus_conn->conn && e_dbus_conn->conn_type == type)
-     return eldbus_connection_ref(e_dbus_conn->conn);
+     {
+        e_dbus_conn->conn_refcount++;
+        return eldbus_connection_ref(e_dbus_conn->conn);
+     }
 
    return NULL;
 }
@@ -31,7 +34,16 @@ E_API void
 e_dbus_conn_connection_unref(Eldbus_Connection *conn)
 {
    if (conn)
-     eldbus_connection_unref(conn);
+     {
+        if (e_dbus_conn->conn_refcount <= 0)
+          {
+             ERR("Invalid unreference of e_dbus_conn ! (conn_refcount=%d)", e_dbus_conn->conn_refcount);
+             return;
+          }
+
+        eldbus_connection_unref(conn);
+        --e_dbus_conn->conn_refcount;
+     }
 }
 
 static void
@@ -68,50 +80,56 @@ _e_dbus_conn_init_done_send(E_DBus_Conn *ed)
 static void
 _e_dbus_conn_init_thread_heavy(void *data, Ecore_Thread *th, void *msg_data)
 {
-   Eina_Bool *res = NULL;
-   E_DBus_Conn ed_thread = *(E_DBus_Conn *)data;
-   int retry_cnt = ed_thread.retry_cnt;
-
-   res = calloc(1, sizeof(Eina_Bool));
+   E_DBus_Conn *ed_thread = (E_DBus_Conn *)data;
+   int retry_cnt;
 
-   if (!res)
+   if (!ed_thread)
      {
-        ERR("Failed to allocate memory for E_DBus_Conn thread !\n");
+        ERR("[E_DBus_Conn] Invalid E_DBus_Conn ptr is given ! Thread is going to canceled !");
+        ecore_thread_cancel(th);
         return;
      }
 
-   *res = EINA_FALSE;
-   ed_thread.conn = NULL;
+   retry_cnt = ed_thread->retry_cnt;
+
+   ed_thread->conn = NULL;
 
    while (retry_cnt--)
      {
-        ed_thread.conn = eldbus_connection_get(ed_thread.conn_type);
+        ed_thread->conn = eldbus_connection_get(ed_thread->conn_type);
 
-        if (ed_thread.conn)
+        if (ed_thread->conn)
           {
-             eldbus_connection_unref(ed_thread.conn);
-             *res = EINA_TRUE;
              break;
           }
 
-        if (ed_thread.retry_intervals)
-          usleep(ed_thread.retry_intervals);
+        if (ed_thread->retry_intervals)
+          usleep(ed_thread->retry_intervals);
      }
 
-   ecore_thread_feedback(th, res);
+   ecore_thread_feedback(th, ed_thread);
+
    return;
 }
 
 static void
 _e_dbus_conn_init_thread_notify(void *data, Ecore_Thread *th, void *msg_data)
 {
-   Eina_Bool *res = (Eina_Bool *)msg_data;
+   E_DBus_Conn *ed_thread = (E_DBus_Conn *)msg_data;
+
+   if (!ed_thread)
+     {
+        ERR("[%s] Invalid E_DBus_Conn ptr !", __FUNCTION__);
+        return;
+     }
 
-   if (res && *res)
+   if (ed_thread->conn)
      {
+        eldbus_connection_unref(ed_thread->conn);
+
         e_dbus_conn->conn = eldbus_connection_get(e_dbus_conn->conn_type);
         if (e_dbus_conn->conn) e_dbus_conn->init_status = E_DBUS_CONN_INIT_SUCCESS;
-        free(res);
+        INF("E_DBus_Conn connection has been got successfully !");
      }
 }
 
@@ -119,6 +137,8 @@ static void
 _e_dbus_conn_init_thread_end(void *data, Ecore_Thread *th, void *msg_data)
 {
    _e_dbus_conn_init_done_send(e_dbus_conn);
+
+   INF("E_DBus_Conn thread has been ended successfully !");
 }
 
 static void
@@ -240,6 +260,7 @@ e_dbus_conn_init(void)
    ed->retry_cnt = E_DBUS_CONN_DEFAULT_RETRY_COUNT;
    ed->init_status = E_DBUS_CONN_INIT_YET_STARTED;
    ed->retry_intervals = 0;
+   ed->conn_refcount = 0;
 
    E_EVENT_DBUS_CONN_INIT_DONE = ecore_event_type_new();
 
@@ -276,7 +297,8 @@ e_dbus_conn_init(void)
 
    e_dbus_conn = ed;
 
-   INF("Succeed to init E_DBus_Conn !");
+   INF("Succeed to init E_DBus_Conn ! (use_thread=%d, retry_intervals=%d, retry_cnt=%d)",
+                                                  ed->use_thread, ed->retry_intervals, ed->retry_cnt);
 
    return _e_dbus_conn_init_count;
 }
index 83b1ba531b66ff3010bb564ea8b342eed06b0747..a5bf7a56e9e976f7b58729f1c84c359b0f39bb62 100644 (file)
@@ -32,6 +32,7 @@ struct _E_DBus_Conn
    Eldbus_Connection *conn;
    Eldbus_Connection_Type conn_type;
    unsigned int retry_intervals; /* suspend re-connection for microsecond intervals */
+   unsigned int conn_refcount;
 };
 
 typedef struct _E_DBus_Conn_Init_Done_Event E_DBus_Conn_Init_Done_Event;