Improve safe initialization of main loop 45/321545/1
authorSeoyeon <seoyeon2.kim@samsung.com>
Tue, 25 Mar 2025 02:20:42 +0000 (11:20 +0900)
committerSeoyeon <seoyeon2.kim@samsung.com>
Tue, 25 Mar 2025 04:52:32 +0000 (13:52 +0900)
- Replace `std::call_once` with `std::thread()` for safer initialization
- Fix potential deadlock when interacting with EFL main loop from Rust

Change-Id: I0b17cd1e7d4bb8b2be0bf268bbe22f5dd71dd305
Signed-off-by: Seoyeon <seoyeon2.kim@samsung.com>
libaurum/src/c_bindings/AurumCBindings.cc

index f819375a17aed839857a92709e6105e2bcc4f7db..a3f3b3f173d684f1068a667b4b1e669c098367d6 100644 (file)
@@ -21,6 +21,8 @@
 
 #ifdef TIZEN
 #include <Ecore.h>
+static std::once_flag init_flag;
+static std::once_flag shutdown_flag;
 #endif
 
 using namespace Aurum;
@@ -28,12 +30,16 @@ using namespace Aurum;
 void aurum_init()
 {
     LOGI("aurum_init");
-    AccessibleWatcher::getInstance();
 // TODO: Move this to Application side.
 #ifdef TIZEN
-    ecore_init();
-    ecore_main_loop_begin();
+    std::call_once(init_flag, []() {
+        ecore_init();
+        std::thread([]() {
+            ecore_main_loop_begin();
+        }).detach();
+    });
 #endif
+    AccessibleWatcher::getInstance();
 }
 
 void aurum_shutdown()
@@ -41,8 +47,13 @@ void aurum_shutdown()
     LOGI("aurum_shutdown");
 // TODO: Move this to Application side.
 #ifdef TIZEN
-    ecore_main_loop_quit();
-    ecore_shutdown();
+    std::call_once(shutdown_flag, []() {
+        std::thread([]() {
+            ecore_main_loop_quit();
+        }).detach();
+
+        ecore_shutdown();
+    });
 #endif
 }