Separate the thread of execution from thread object 97/319697/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 30 Oct 2024 10:08:39 +0000 (19:08 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 30 Oct 2024 10:11:05 +0000 (19:11 +0900)
If the current thread is equal to the thread object, the task
calls thread_.dectach() to separate the thread of execution from the
thread object.

Change-Id: I89587f554bb8dc69381e8af814e96d0970186951
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/tizen-core/task.cc

index 3648bd05f971e16f1049a86b2eb4240ec976c7a1..8c9656c4748c751f05f88b276ca5af68e08be5ed 100644 (file)
@@ -210,8 +210,12 @@ Task::Task(std::string name, bool use_thread)
 Task::~Task() {
   _W("~Task: %s", name_.c_str());
   Quit();
-  if (use_thread_ && thread_.joinable())
-    thread_.join();
+  if (use_thread_ && thread_.joinable()) {
+    if (pthread_self() == thread_.native_handle())
+      thread_.detach();
+    else
+      thread_.join();
+  }
 
   g_main_loop_unref(loop_);
 }
@@ -384,6 +388,7 @@ bool Task::ClearCpuBoosting() {
 // LCOV_EXCL_STOP
 
 void Task::ThreadLoop() {
+  _D("[%s] BEGIN", name_.c_str());
   {
     std::unique_lock<std::mutex> lock(loop_mutex_);
     GSource* source = g_idle_source_new();
@@ -411,6 +416,7 @@ void Task::ThreadLoop() {
     g_main_context_dispatch(context_->GetHandle());
 
   g_main_context_pop_thread_default(context_->GetHandle());
+  _D("[%s] END", name_.c_str());
 }
 
 void Task::AddEventSource(std::shared_ptr<ISource> source) {