Fix GMainContext creation 35/253035/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Feb 2021 03:43:10 +0000 (12:43 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Feb 2021 03:43:10 +0000 (12:43 +0900)
To separate the context from the existed main context,
the MainLoop class always creates the GMainContext.

Change-Id: I1b4bd789c1cac7ca15a9db0e5eaf8d5e7974b551
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
component_based/port/main_loop.cc
component_based/port/main_loop.hh

index 7b373c97d52cd5e3ec4cc68c6eaff24c201288ea..0a465ad3cbcac313052bebddfeb60a5ebc68c992 100644 (file)
 
 namespace component_based {
 
-MainLoop::MainLoop() = default;
+MainLoop::MainLoop() {
+  context_ = g_main_context_new();
+}
 
 MainLoop::~MainLoop() {
-  if (thread_default_)
-    g_main_context_pop_thread_default(context_);
-
   if (loop_) {
     if (g_main_loop_is_running(loop_))
       g_main_loop_quit(loop_);
@@ -40,22 +39,10 @@ MainLoop::~MainLoop() {
 }
 
 void MainLoop::Run() {
-  if (context_ == nullptr) {
-    if (gettid() != getpid()) {
-      _W("Sub thread");
-      context_ = g_main_context_get_thread_default();
-      if (context_ == nullptr) {
-        context_ = g_main_context_new();
-        g_main_context_push_thread_default(context_);
-        thread_default_ = true;
-      } else {
-        context_ = g_main_context_ref_thread_default();
-      }
-    } else {
-      _W("Main thread");
-      context_ = g_main_context_ref(g_main_context_default());
-    }
-  }
+  if (gettid() != getpid())
+    _W("Sub thread");
+  else
+    _W("Main thread");
 
   if (loop_ == nullptr)
     loop_ = g_main_loop_new(context_, FALSE);
index e475ca44f6d73d713a3cb1133f4ab54550f8cd16..06060f35ad6d12fb59bd2b1cf89d7fddbf930ebc 100644 (file)
@@ -32,7 +32,6 @@ class MainLoop {
   GMainContext* GetContext() const;
 
  private:
-  bool thread_default_ = false;
   GMainContext* context_ = nullptr;
   GMainLoop* loop_ = nullptr;
 };