Check a task status inside HandleExt to handle concurrent issue
[platform/upstream/csr-framework.git] / src / framework / client / handle-ext.cpp
index 66a9273..cf97924 100644 (file)
@@ -47,12 +47,16 @@ void HandleExt::setStopFunc(std::function<void()> &&func)
        this->m_stopFunc = std::move(func);
 }
 
-void HandleExt::stop()
+bool HandleExt::stop()
 {
        DEBUG("Stop & join worker...");
 
        {
                std::lock_guard<std::mutex> l(this->m_flagMutex);
+
+               if (!this->m_isRunning || this->m_stop)
+                       return false;
+
                this->m_stop = true;
 
                if (this->m_stopFunc != nullptr)
@@ -61,6 +65,8 @@ void HandleExt::stop()
 
        if (this->m_worker.joinable())
                this->m_worker.join();
+
+       return true;
 }
 
 bool HandleExt::isStopped() const