Set app state while calling loop exit function 38/283938/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 7 Nov 2022 11:04:22 +0000 (11:04 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 7 Nov 2022 11:04:22 +0000 (11:04 +0000)
While calling the serivce_app_exit(), the app state is updated to
APP_STATE_NOT_RUNNING. It's to prevent the function from being calling twice.

Change-Id: I6935077c9505c50894aaaf2eebc2eb7372c89c91
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/service_app_main.cc

index 2e7335b..301c3c4 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <list>
 #include <memory>
+#include <mutex>
 #include <type_traits>
 
 #include "service_app_extension.h"
@@ -159,17 +160,21 @@ class AppContext : public AppCoreBase {
   }
 
   void OnLoopInit(int argc, char** argv) override {
-    if (method_.init)
+    if (method_.init) {
       method_.init(argc, argv, data_);
-    else
+    } else {
+      _W("ecore_init");
       ecore_init();
+    }
   }
 
   void OnLoopFinish() override {
-    if (method_.fini)
+    if (method_.fini) {
       method_.fini();
-    else
+    } else {
+      _W("ecore_shutdown");
       ecore_shutdown();
+    }
   }
 
   void OnLoopRun() override {
@@ -180,6 +185,7 @@ class AppContext : public AppCoreBase {
   }
 
   void OnLoopExit() override {
+    SetAppState(APP_STATE_NOT_RUNNING);
     if (method_.exit) {
       method_.exit(data_);
     } else {
@@ -195,6 +201,7 @@ class AppContext : public AppCoreBase {
   }
 
   void SetAppState(AppState state) {
+    std::lock_guard<std::recursive_mutex> lock(mutex_);
     state_ = state;
   }
 
@@ -203,6 +210,7 @@ class AppContext : public AppCoreBase {
   service_app_loop_method_s method_;
   void* data_;
   AppState state_ = APP_STATE_NOT_RUNNING;
+  mutable std::recursive_mutex mutex_;
 };
 
 std::unique_ptr<AppContext> __context;