Modify aul_app_com_leave function
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 8 Mar 2023 10:15:22 +0000 (10:15 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 Jan 2024 23:59:03 +0000 (08:59 +0900)
Some program goes to the sleep state immediately after calling
the aul_app_com_leave() function. In this case, the main thread of the
process will be blocked. It causes increasing memory usage.
To avoid the issue, the aul_app_com_leave() function sends the
APP_COM_LEAVE command to the amd to deregister the event.

Change-Id: Ic3d27b8c4151955094887fea59ed25cda08d2faf
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/app_com.cc

index e1e2645c21d196a3fd56f22c9a4c9cc7b2aee301..340c13004b81fd24e8c4780cc727ad627dc7532c 100644 (file)
@@ -21,6 +21,7 @@
 #include <mutex>
 #include <string>
 
+#include "app_request.h"
 #include "aul_api.h"
 #include "aul_util.h"
 #include "include/aul.h"
@@ -331,9 +332,20 @@ extern "C" API int aul_app_com_leave(aul_app_com_connection_h connection) {
 
   std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
   conn->Disable();
+
   std::string endpoint = conn->GetEndpoint();
+  if (!context.ExistConnection(endpoint)) {
+    tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } };
+    int ret = aul::internal::AppRequest(APP_COM_LEAVE, getuid())
+      .With(std::move(b))
+      .SendSimply(AUL_SOCK_NOREPLY);
+    if (ret != 0)
+      _E("Failed to send leave request. error(%d)", ret);
+  }
+
   g_idle_add_full(G_PRIORITY_HIGH, [](gpointer user_data) -> gboolean {
         auto* conn = static_cast<AppComConnection*>(user_data);
+        std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
         context.RemoveConnection(conn);
         return G_SOURCE_REMOVE;
       }, connection, nullptr);