Check calling thread ID
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 31 Mar 2025 07:25:07 +0000 (16:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 31 Mar 2025 07:25:07 +0000 (16:25 +0900)
If it's equal to the caller thread, we should skip calling
std::conditional_variable.wait().

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/service.cc
src/service.hh

index ba764c965582832c9d2b032b1f80123c161e7a92..5351531f9b1dd91395f5fb9d3925b6c8d317546c 100644 (file)
@@ -107,6 +107,7 @@ void Service::Run() {
   tizen_core_add_idle_job(
       core_, [](void* user_data) -> bool {
         auto* service = static_cast<Service*>(user_data);
+        service->tid_ = gettid();
         service->OnCreate();
         service->state_ = Service::State::Running;
         ServiceManager::GetInst().NotifyServiceStateChanged(service);
@@ -130,6 +131,7 @@ void Service::Quit() {
       core_,
       [](void* user_data) -> bool {
         auto* service = static_cast<Service*>(user_data);
+        std::unique_lock<std::mutex> idle_lock(service->mutex_);
         service->OnDestroy();
         service->cond_var_.notify_one();
         return false;
@@ -137,7 +139,9 @@ void Service::Quit() {
       this, &source);
 
   tizen_core_task_quit(task_);
-  cond_var_.wait(lock, [this]() { return state_ == State::Destroyed; });
+  if (gettid() != tid_)
+    cond_var_.wait(lock, [this]() { return state_ == State::Destroyed; });
+
   running_ = false;
 }
 
index fab5cfd1b6884852faf47a7934e65f457453e75d..354ad592e084efe2c5dae75f0179d0de4d3eb365 100644 (file)
@@ -71,6 +71,7 @@ class Service : public std::enable_shared_from_this<Service> {
   bool running_ = false;
   std::mutex mutex_;
   std::condition_variable cond_var_;
+  pid_t tid_ = -1;
 };
 
 } // namespace tizen_base