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_);
}
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);