Modify ANR Monitor feature 70/314070/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Jul 2024 23:14:30 +0000 (08:14 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Jul 2024 23:51:07 +0000 (08:51 +0900)
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 <h.jhun@samsung.com>
src/aul/anr_monitor.cc
src/aul/aul_launch.c

index dcacd016424586dfe9d731ed560f96fee777eea6..13cce835d362a287edc26ebc1aa111725cf7b8c5 100644 (file)
@@ -138,29 +138,18 @@ gboolean AnrMonitor::IdleCb(gpointer user_data) {
   std::lock_guard<std::recursive_mutex> lock(anr_monitor.GetRecMutex());
   GSource* source = static_cast<GSource*>(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<AnrMonitor*>(user_data);
-  std::lock_guard<std::recursive_mutex> lock(self->GetRecMutex());
-  auto* idle_source = self->GetIdleSource();
+  std::lock_guard<std::recursive_mutex> 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();
index 875d68a13aa9ec0244ca23c87963f3666937c18d..309d94dd7c594f0305f6ad4dddba1f9db8d25b8b 100644 (file)
@@ -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;