From 8d0c121afcac5a2365e6cec3dce95703af1d9379 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 19 Mar 2025 08:00:22 -0400 Subject: [PATCH] MT#62181 global: fix AmThread/AmEventQueue order Classes that inherit from both AmThread and AmEventHandler must inherit from AmEventQueue first and from AmThread after. This is needed so that the AmThread dtor is called first, which will trigger the thread to shut down, which in turn makes sure nothing is waiting on the AmEventQueue's condition variable. Otherwise, if AmEventQueue is destroyed first while the corresponding thread is still running and waiting on the condition variable, it will be a deadlock. With this, sems finally can shut down cleanly without having to be killed by systemd. Change-Id: I914455763b517c96561acb0b64fce26f127f44bc --- apps/db_reg_agent/DBRegAgent.h | 6 +++--- apps/diameter_client/ServerConnection.h | 4 ++-- apps/dsm/SystemDSM.h | 4 ++-- apps/jsonrpc/RpcServerLoop.h | 2 +- apps/jsonrpc/RpcServerThread.h | 2 +- apps/xmlrpc2di/XMLRPC2DI.h | 4 ++-- core/AmCallWatcher.h | 4 ++-- core/AmSession.h | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/db_reg_agent/DBRegAgent.h b/apps/db_reg_agent/DBRegAgent.h index dadf86e4..334d399d 100644 --- a/apps/db_reg_agent/DBRegAgent.h +++ b/apps/db_reg_agent/DBRegAgent.h @@ -97,8 +97,8 @@ class DBRegAgent; // separate thread for REGISTER sending, which can block for rate limiting class DBRegAgentProcessorThread -: public AmThread, - public AmEventQueue, +: public AmEventQueue, + public AmThread, public AmEventHandler { @@ -126,8 +126,8 @@ class RegTimer; class DBRegAgent : public AmDynInvokeFactory, public AmDynInvoke, - public AmThread, public AmEventQueue, + public AmThread, public AmEventHandler { diff --git a/apps/diameter_client/ServerConnection.h b/apps/diameter_client/ServerConnection.h index f71d5180..bd808185 100644 --- a/apps/diameter_client/ServerConnection.h +++ b/apps/diameter_client/ServerConnection.h @@ -93,8 +93,8 @@ struct DiameterServerConnection { }; class ServerConnection -: public AmThread, - public AmEventQueue, +: public AmEventQueue, + public AmThread, public AmEventHandler { struct timeval connect_ts; diff --git a/apps/dsm/SystemDSM.h b/apps/dsm/SystemDSM.h index 8821eb3c..1d5f29e2 100644 --- a/apps/dsm/SystemDSM.h +++ b/apps/dsm/SystemDSM.h @@ -24,8 +24,8 @@ class EventProxySession }; class SystemDSM -: public AmThread, - public AmEventQueue, +: public AmEventQueue, + public AmThread, public AmEventHandler, public DSMSession diff --git a/apps/jsonrpc/RpcServerLoop.h b/apps/jsonrpc/RpcServerLoop.h index 27776a8e..799a5d7b 100644 --- a/apps/jsonrpc/RpcServerLoop.h +++ b/apps/jsonrpc/RpcServerLoop.h @@ -44,7 +44,7 @@ #include class JsonRPCServerLoop -: public AmThread, public AmEventQueue, public AmEventHandler +: public AmEventQueue, public AmThread, public AmEventHandler { static RpcServerThreadpool threadpool; static ev_async async_w; diff --git a/apps/jsonrpc/RpcServerThread.h b/apps/jsonrpc/RpcServerThread.h index 79dd8ee5..72e81007 100644 --- a/apps/jsonrpc/RpcServerThread.h +++ b/apps/jsonrpc/RpcServerThread.h @@ -36,7 +36,7 @@ #include "RpcPeer.h" class RpcServerThread -: public AmThread, public AmEventQueue, public AmEventHandler +: public AmEventQueue, public AmThread, public AmEventHandler { char rcvbuf[MAX_RPC_MSG_SIZE]; diff --git a/apps/xmlrpc2di/XMLRPC2DI.h b/apps/xmlrpc2di/XMLRPC2DI.h index 9ac1f7fe..ba6cd946 100644 --- a/apps/xmlrpc2di/XMLRPC2DI.h +++ b/apps/xmlrpc2di/XMLRPC2DI.h @@ -96,8 +96,8 @@ struct DIMethodProxy : public XmlRpcServerMethod }; class XMLRPC2DIServer -: public AmThread, - public AmEventQueue, +: public AmEventQueue, + public AmThread, public AmEventHandler { XmlRpcServer* s; diff --git a/core/AmCallWatcher.h b/core/AmCallWatcher.h index e0ff62e5..85dcfc87 100644 --- a/core/AmCallWatcher.h +++ b/core/AmCallWatcher.h @@ -107,8 +107,8 @@ class AmCallWatcherGarbageCollector; * reporting the status change. */ class AmCallWatcher -: public AmThread, - public AmEventQueue, +: public AmEventQueue, + public AmThread, public AmEventHandler { public: diff --git a/core/AmSession.h b/core/AmSession.h index 8c136702..5e90a19e 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -66,10 +66,10 @@ class AmDtmfEvent; */ class AmSession : public virtual AmObject, + public AmEventQueue, #ifndef SESSION_THREADPOOL public AmThread, #endif - public AmEventQueue, public AmEventHandler, public AmSipDialogEventHandler, public AmMediaSession,