From 2a1d878444d31953a5dfc298fd06cb8d6b2c0c55 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 16 Jun 2023 01:08:14 +0000 Subject: [PATCH] Modify AppCoreUiThreadBase class To use the Post() method before calling the Run() method, the GMainContext should be created when the instance is created. Change-Id: I6638965e671ee83b1691fd64e9615ed441e3afa0 Signed-off-by: Hwankyu Jhun --- .../app-core-ui-cpp/app_core_ui_thread_base.cc | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tizen-cpp/app-core-ui-cpp/app_core_ui_thread_base.cc b/tizen-cpp/app-core-ui-cpp/app_core_ui_thread_base.cc index 2b3fe35..67bd5bf 100644 --- a/tizen-cpp/app-core-ui-cpp/app_core_ui_thread_base.cc +++ b/tizen-cpp/app-core-ui-cpp/app_core_ui_thread_base.cc @@ -38,33 +38,43 @@ AppCoreUiThreadBase* context = nullptr; class AppCoreUiThreadBase::Impl { public: - Impl(AppCoreUiThreadBase* parent) : parent_(parent) {} + Impl(AppCoreUiThreadBase* parent) : parent_(parent) { + context_ = g_main_context_new(); + std::string context_str = std::to_string( + reinterpret_cast(context_)); + setenv("TIZEN_GLIB_CONTEXT", context_str.c_str(), 1); + } ~Impl() { if (thread_.joinable()) thread_.join(); + + if (context_ != nullptr) { + setenv("TIZEN_GLIB_CONTEXT", "0", 1); + g_main_context_unref(context_); + } } void Run(int argc, char** argv) { - if (context_ != nullptr) { + if (running_) { _E("Already running"); return; } - context_ = g_main_context_new(); - std::string context_str = std::to_string( - reinterpret_cast(context_)); - setenv("TIZEN_GLIB_CONTEXT", context_str.c_str(), 1); - + running_ = true; thread_ = std::thread([&] { pthread_setname_np(pthread_self(), "UIThread+"); parent_->OnLoopInit(argc, argv); parent_->OnLoopRun(); + running_ = false; parent_->OnLoopFinish(); }); } void Exit() { + if (!running_) + return; + parent_->OnLoopExit(); } @@ -90,6 +100,7 @@ class AppCoreUiThreadBase::Impl { std::thread thread_; GMainContext* context_ = nullptr; tizen_base::SharedQueue queue_; + bool running_ = false; }; AppCoreUiThreadBase::AppCoreUiThreadBase() : impl_(new Impl(this)) { -- 2.7.4