Check a task status inside HandleExt to handle concurrent issue 06/120006/1
authorDongsun Lee <ds73.lee@samsung.com>
Sun, 19 Mar 2017 04:58:53 +0000 (13:58 +0900)
committerDong Sun Lee <ds73.lee@samsung.com>
Tue, 21 Mar 2017 06:33:21 +0000 (23:33 -0700)
Change-Id: I46211a78f6b43cf8da0e001b3e511e765d981d70
Signed-off-by: Dongsun Lee <ds73.lee@samsung.com>
(cherry picked from commit 9f8be3f00c3dc9446f8b7abad887871ad3224804)

src/framework/client/content-screening.cpp
src/framework/client/handle-ext.cpp
src/framework/client/handle-ext.h

index 17d518a..f682cc9 100644 (file)
@@ -491,11 +491,9 @@ int csr_cs_cancel_scanning(csr_cs_context_h handle)
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
 
-       if (!hExt->isRunning() || hExt->isStopped())
+       if (!hExt->stop())
                return CSR_ERROR_NO_TASK;
 
-       hExt->stop();
-
        return CSR_ERROR_NONE;
 
        EXCEPTION_SAFE_END
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
index 31efdf9..c9df5a8 100644 (file)
@@ -38,7 +38,7 @@ public:
 
        void dispatchAsync(const std::shared_ptr<Task> &task);
        void setStopFunc(std::function<void()> &&func);
-       void stop(void);
+       bool stop(void);
        bool isStopped(void) const;
        bool isRunning(void) const;