From c41e96bf3d73b6fd96b2ffada2627b16ab444751 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 5 Jul 2024 08:14:30 +0900 Subject: [PATCH] Modify ANR Monitor feature If the caller is a daemon, the aul does not initialize the anr monitor. Some daemon does not use the GMainLoop. And, ANR Monitor does not remove the registered GSource using g_source_destroy(). The GSource will be destroyed automatically in the callback function. Change-Id: I93b99f2a694fb3d57530ee96e55f8de86f1fa83c Signed-off-by: Hwankyu Jhun --- src/aul/anr_monitor.cc | 17 +++-------------- src/aul/aul_launch.c | 4 +++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/aul/anr_monitor.cc b/src/aul/anr_monitor.cc index dcacd01..13cce83 100644 --- a/src/aul/anr_monitor.cc +++ b/src/aul/anr_monitor.cc @@ -138,29 +138,18 @@ gboolean AnrMonitor::IdleCb(gpointer user_data) { std::lock_guard lock(anr_monitor.GetRecMutex()); GSource* source = static_cast(user_data); GSource* idle_source = anr_monitor.GetIdleSource(); - if (source != idle_source) { - if (!g_source_is_destroyed(source)) - g_source_destroy(source); + if (source == idle_source) anr_monitor.SetIdleSource(nullptr); - return G_SOURCE_CONTINUE; - } - - anr_monitor.SetIdleSource(nullptr); return G_SOURCE_REMOVE; } gboolean AnrMonitor::TimeoutCb(gpointer user_data) { - auto* self = static_cast(user_data); - std::lock_guard lock(self->GetRecMutex()); - auto* idle_source = self->GetIdleSource(); + std::lock_guard lock(anr_monitor.GetRecMutex()); + auto* idle_source = anr_monitor.GetIdleSource(); if (idle_source != nullptr) { _E("[ANR] The main thread is unable to enter idle state."); _E("[ANR] Please modify the implementation so that the main loop does not " "create a block state."); - if (!g_source_is_destroyed(idle_source)) - g_source_destroy(idle_source); - - anr_monitor.SetIdleSource(nullptr); } anr_monitor.AddIdlerToDefaultContext(); diff --git a/src/aul/aul_launch.c b/src/aul/aul_launch.c index 875d68a..309d94d 100644 --- a/src/aul/aul_launch.c +++ b/src/aul/aul_launch.c @@ -732,7 +732,9 @@ static int __initialize_context(void) return ret; } - aul_anr_monitor_init(); + if (getenv("AUL_APPID")) + aul_anr_monitor_init(); + __context.initialized = true; return AUL_R_OK; -- 2.7.4