From: Hwankyu Jhun Date: Wed, 6 Oct 2021 23:33:06 +0000 (+0900) Subject: Use destructor attribute for disposing thread X-Git-Tag: submit/tizen/20211028.054746~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e93c2abbfa54d7115abb46f4caf5689dac75db0f;p=platform%2Fcore%2Fappfw%2Frpc-port.git Use destructor attribute for disposing thread The rpc-port library can be loaded and unloaded using dlopen() and dlclose() in the runtime. In this case, the process has crashed by the thread of the rpc-port library. Before unloading the library, the thread has to be terminated. This patch uses destructor attribute to terminate the thread appropriately before unloading the library is finished. Change-Id: I2338a4419f02fb67dff042fd308ba1d590bf0ac3 Signed-off-by: Hwankyu Jhun --- diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index ddfd930..2f3219e 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -25,19 +25,26 @@ #include "debug-port-internal.hh" #include "log-private.hh" +#undef RPC_DTOR +#define RPC_DTOR __attribute__ ((destructor)) + namespace rpc_port { namespace internal { namespace { const char PATH_RPC_PORT_UTIL_SOCK[] = "/run/aul/daemons/.rpc-port-util-sock"; + +RPC_DTOR void DebugPortDtor() { + DebugPort::GetInst()->Dispose(); +} + } // namespace std::atomic DebugPort::inst_; std::mutex DebugPort::mutex_; DebugPort::~DebugPort() { - if (!disposed_) - Dispose(); + Dispose(); } DebugPort* DebugPort::GetInst() { @@ -59,6 +66,10 @@ DebugPort* DebugPort::GetInst() { } void DebugPort::Dispose() { + std::lock_guard lock(GetMutex()); + if (disposed_) + return; + Unwatch(); JoinThread(); disposed_ = true;