Check current thread ID to destroy handle 27/262927/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 23 Aug 2021 22:44:16 +0000 (07:44 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 23 Aug 2021 23:58:42 +0000 (08:58 +0900)
If the current thread ID is equal to the process ID,
the destroy functions destroy the handle immediately.
If it's not, the rpc-port uses glib idler to destroy the handle
in the main thread.

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

index d02fc44..f4c5a35 100644 (file)
@@ -17,6 +17,8 @@
 #include <aul.h>
 #include <aul_rpc_port.h>
 #include <glib.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include <atomic>
 #include <mutex>
@@ -292,9 +294,13 @@ RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) {
   auto p = static_cast<std::shared_ptr<::ProxyExt>*>(h);
   auto* proxy = p->get();
   _W("rpc_port_proxy_destroy(%p)", proxy);
+  if (getpid() == gettid()) {
+    delete p;
+    return RPC_PORT_ERROR_NONE;
+  }
+
   proxy->SetDestroying(true);
   proxy->DisconnectPort();
-
   g_idle_add_full(G_PRIORITY_HIGH,
       [](gpointer data) -> gboolean {
         auto p = static_cast<std::shared_ptr<::ProxyExt>*>(data);
@@ -302,6 +308,7 @@ RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) {
         delete p;
         return G_SOURCE_REMOVE;
       }, h, nullptr);
+
   return RPC_PORT_ERROR_NONE;
 }
 
@@ -424,9 +431,13 @@ RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
   _W("rpc_port_stub_destroy(%p)", h);
   auto p = static_cast<::StubExt*>(h);
   aul_rpc_port_usr_destroy(p->GetPortName().c_str(), rpc_port_get_target_uid());
+  if (getpid() == gettid()) {
+    delete p;
+    return RPC_PORT_ERROR_NONE;
+  }
+
   p->Ignore();
   p->SetDestroying(true);
-
   g_idle_add_full(G_PRIORITY_HIGH,
       [](gpointer data) -> gboolean {
         auto p = static_cast<::StubExt*>(data);
@@ -434,6 +445,7 @@ RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
         delete p;
         return G_SOURCE_REMOVE;
       }, h, nullptr);
+
   return RPC_PORT_ERROR_NONE;
 }